Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to parse dict output in a user friendly way in PHP?
    primarykey
    data
    text
    <p>I am trying to implement a dictionary-type service. I send a request with php using cURL to dict.org with the dict protocol. This is my code (which on its own works and may be helpful for future readers):</p> <pre><code>$ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "dict://dict.org/define:(hello):english:exact"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $definition = curl_exec($ch); curl_close($ch); echo $definition; </code></pre> <p>The server returns the definition, as expected, along with several headers (that I do not need). The response looks something like this:</p> <pre><code>220 miranda.org dictd 1.9.15/rf on Linux 2.6.26-2-686 &lt;auth.mime&gt; &lt;29631663.31530.1250750274@miranda.org&gt; 250 ok 150 3 definitions retrieved 151 "Hello" gcide "The Collaborative International Dictionary of English v.0.48" Hello \Hel*lo"\, interj. &amp; n. An exclamation used as a greeting, to call attention, as an exclamation of surprise, or to encourage one. This variant of {Halloo} and {Holloo} has become the dominant form. In the United States, it is the most common greeting used in answering a telephone. [1913 Webster +PJC] (... some content removed) . 250 ok [d/m/c = 3/0/162; 0.000r 0.000u 0.000s] 221 bye [d/m/c = 0/0/0; 0.000r 0.000u 0.000s] </code></pre> <p>I was wondering if:</p> <p>a) Is there a way to specify to curl (or an option in the dict protocol) to not return all that extra information (i.e. <code>250 ok [d/m/c = 3/0/162; 0.000r...]</code>)</p> <p>b) You probably noticed that the dict response returns information that is not displayed in the most user friendly way. I was wondering if anybody knew of any existing php library that will allow me to display this in a nicer way. Otherwise I'd have to code my own.</p> <p>c) If this is not the way most dictionary websites retrieve their definitions, how do they do it? In my understanding the most comprehensive dictionary database is the one at dict.org (which supports the <a href="http://tools.ietf.org/html/rfc2229" rel="nofollow noreferrer">dict protocol</a> and is where I am sending my cURL request).</p> <p>Thank you!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload