开发者

How to get the title of an article using regex?

开发者 https://www.devze.com 2023-03-28 15:54 出处:网络
I want to get the title of an article from this page using regex and simplehtmldom :http://laperuanavegana.wordpress.com/about/

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

精彩评论

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