开发者

How to get the title of an article using regex?

I want to get the title of an article from this page using regex and simplehtmldom : http://laperuanavegana.wordpress.com/about/

in this case title is : Cómo preparar SEITÁN

Here is my regex :

$html = file_get_html($url);
preg_match_all("title=(.*?)",$html->innertext,$title);
echo "this is title ".$title[0开发者_如何学编程][0]."<br>";

It would be helpful if anyone help me to find the bug.


I think you need to look for text between <title> and </title>, not for text following title=.

For example:

$html = "Sometext<title>Seitan</title>More text";
preg_match_all('|<title>(.*?)</title>|',$html,$title);
echo "this is title ".$title[1][0]."<br>";
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜