我想實現一個字典型服務。 我使用cURL向dict.org發送了使用dict協議的php請求。 這是我的代碼(這對自己的作品,並可能對未來的讀者有所幫助):如何在PHP中以用戶友好的方式解析dict輸出?
$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;
服務器返回的定義,符合市場預期,與幾個頭沿(即我不需要)。響應看起來是這樣的:
220 miranda.org dictd 1.9.15/rf on Linux 2.6.26-2-686 <auth.mime> <[email protected]>
250 ok
150 3 definitions retrieved
151 "Hello" gcide "The Collaborative International Dictionary of English v.0.48"
Hello \Hel*lo"\, interj. & 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]
我在想,如果:
一)有沒有一種方法來指定捲曲(或字典協議的選項)來無回所有額外信息(即250 ok [d/m/c = 3/0/162; 0.000r...]
)
b)您可能注意到,字典響應返回的信息不是以用戶友好的方式顯示的。我想知道是否有人知道任何現有的PHP庫,這將允許我以更好的方式顯示這個。否則,我不得不編碼我自己的。
c)如果這不是大多數字典網站檢索他們的定義的方式,他們是如何做到的?在我的理解中,最全面的字典數據庫是dict.org(它支持dict protocol,並且是我發送我的cURL請求的地方)。
謝謝!
謝謝!你碰巧知道做什麼? –
2009-08-21 19:22:02
這正是我如何去做的。謝謝! – 2009-08-22 20:48:44