php - Programmatically fetching definition of a word -
php - Programmatically fetching definition of a word -
i writing social app people utilize tags organizing articles. these tags shared across site , each tag needs have description it.
i wonder if there way can programmatically fetch resource wikipedia. (say first paragraph).
the tags typically associated brands products , services.
yes can
<?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
edit: looks don't non-validated browser agents. you'll have curl edit2: curl 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
php javascript api rest
Comments
Post a Comment