捕獲標籤我用這個功能來讀取和顯示信息,我想從RSS VIMEO:用的preg_match
$url=array('http://vimeo.com/channels/hdnature/videos/rss');
foreach($url as $value){
$homepage = file_get_contents($value);
$movies = new SimpleXMLElement($homepage);
foreach($movies->channel->item as $opt){
$title= $opt->title;
$tittle=mysql_real_escape_string($title);
$link=$opt->link;
$links=mysql_real_escape_string($link);
$des=$opt->description;
$dess=mysql_real_escape_string($des);
//Use that namespace
$namespaces = $opt->getNameSpaces(true);
//Now we don't have the URL hard-coded
$dc = $opt->children($namespaces['dc']);
//echo $dc->publisher;
//echo $dc->creator;
//echo $link;
$imgpattern = '/href="(.*?)"/i';
preg_match($imgpattern, $des, $matches);
$imageurl['image'] = $matches[1];
echo $imageurl['image'];
$tag = '/">(.*?)<\/a>/';
preg_match($tag, $des, $matches);
$tagurl['name'] = $matches[1];
echo $tagurl['name'];
我有<description></description>
領域內的標籤這個名單:
<p><strong>Tags:</strong>
<a href="http://vimeo.com/tag:art">Art</a>,
<a href="http://vimeo.com/tag:film">Film</a>,
<a href="http://vimeo.com/tag:movie">Movie</a>,
<a href="http://vimeo.com/tag:cinema">Cinema</a>,
<a href="http://vimeo.com/tag:creation">Creation</a>,
<a href="http://vimeo.com/tag:concept">Concept</a>,
<a href="http://vimeo.com/tag:experimental">Experimental</a>,
<a href="http://vimeo.com/tag:sound">Sound</a>,
<a href="http://vimeo.com/tag:music">Music</a>,
<a href="http://vimeo.com/tag:motion">Motion</a>,
<a href="http://vimeo.com/tag:copyleft">Copyleft</a>
and
<a href="http://vimeo.com/tag:videoart">Videoart</a>
</p>
我搜到保存在我的數據庫中只有像藝術,電影,電影等字。
我需要用方括號保存列表,我嘗試使用preg_match。
我有這樣的功能:
$tag = '/</strong>(.*?)</a></p>/';
preg_match($tag, $des, $matches);
$taglist['name'] = $matches[1];
echo $taglist['name'];
但我只收到一個錯誤,而不是結果,我希望的。
我想儲存在我的數據庫中的所有單詞標記之前我發現:whitout鏈接和獨立絲毫括號是這樣的:cineme,ARTE,電影,體育,等等。 – junkfood 2013-02-17 01:45:49
是的,我想店「標籤:」之後的所有單詞,你可以解釋我如何做到這一點? – junkfood 2013-02-18 15:13:56
**不要使用正則表達式來解析HTML **。您無法可靠地使用正則表達式解析HTML。只要HTML從你的期望改變,你的代碼就會被破壞。有關如何使用PHP模塊正確解析HTML的示例,請參閱http://htmlparsing.com/php.html。 – 2013-02-18 17:04:18