以编程方式获取单词的定义


Programmatically fetching definition of a word

我正在编写一个社交应用程序,人们将使用标签来组织他们的文章。这些标签在整个网站上共享,每个标签都需要有一些描述。

我想知道是否有任何方法我可以从像维基百科这样的资源编程获取它。(说第一段)。

标签通常与品牌、产品和服务相关。

可以

<?php
$contents = file_get_contents("http://en.wikipedia.org/wiki/PHP");
preg_match("/<p>(.*?)<'/p>/", $contents, $match);
echo $match[1];
?>
http://sandbox.phpcode.eu/g/45c56.php

编辑:看起来他们不喜欢未经验证的浏览器代理。你得用卷发来做编辑2:curl with browser agent:

<?php
$ch = curl_init("http://en.wikipedia.org/wiki/PHP");
$useragent="Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1";
curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$contents = curl_exec($ch);
preg_match("/<p>(.*?)<'/p>/", $contents, $match);
$match[1] = preg_replace("|'[[0-9]']|", "", strip_tags($match[1]));
echo (($match[1]));
?>
http://sandbox.phpcode.eu/g/ad578.php