[英]Capture Tags with preg_match
I use this function for reading and show information I want from RSS vimeo: 我使用此功能从RSS vimeo中读取和显示所需的信息:
$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'];
I have this list of tags inside the <description></description>
field: 我在
<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>
I search to save in my database only word like Art, Movie, Cinema, etc. 我搜索仅将Art,Movie,Cinema等词保存在数据库中。
I need to save a list with brackets and I try to use preg_match. 我需要保存带有方括号的列表,然后尝试使用preg_match。
I have this function: 我有这个功能:
$tag = '/</strong>(.*?)</a></p>/';
preg_match($tag, $des, $matches);
$taglist['name'] = $matches[1];
echo $taglist['name'];
but I receive only a error and not the result I'm hoping for. 但我只会收到一个错误,而不是我希望得到的结果。
Try this 尝试这个
$des = '<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>';
$tag = '/">(.*?)<\/a>/';
preg_match_all($tag, $des, $matches);
print_r($matches[1]);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.