Ask a regular expression question. what is wrong ;? Php & nbsp; $ str & nbsp; = & nbsp; file_get_contents ("http://mil.news.sina.com.cn"); // & nbsp; military hotspot & ask a regular expression question. what is wrong?
$ Str = file_get_contents ("http://mil.news.sina.com.cn ");
// Military hotspot
$ Reg = '# [military hotspot]. * (. *) "# iUs ';
Preg_match_all ($ reg, $ str, $ m );
Echo"";
print_r($m);
?>
I would like to ask why I did not share the link with the title:
------ Solution --------------------
$ Str = file_get_contents ("http://mil.news.sina.com.cn ");
// Military hotspot
$ Reg = '# [military hotspots]. +? Href = (\ S +) # is ';
Preg_match_all ($ reg, $ str, $ m );
Print_r ($ m );
Array
(
[0] => Array
(
[0] => [military hotspot ])
[1] => Array
(
Http://blog.sina.com.cn/s/blog_69710d610101fglf.html? Tj = 1
)
)
------ Solution --------------------
Reference:
$ Str = file_get_contents ("http://mil.news.sina.com.cn ");
$ Reg = '#(? <= [Military hotspot]). * (. + )(? = Famous column) # isU ';
Preg_match_all ($ reg, $ str, $ m );
Echo"";
print_r($m);
?>
I did not try to write it like this. please take a look.
Its connection does not include quotation marks.
$ Reg = '#(? <= [Military hotspot]). * (. + )(? = Famous column) # isU ';
------ Solution --------------------
$ S_html = file_get_contents ("http://mil.news.sina.com.cn ");
$ S_html = iconv ('gbk', 'utf-8', $ s_html );
$ S_gd_reg = '# [military hotspot ](.*)# IUs ';
$ A_gd_match = array ();
Preg_match_all ($ s_gd_reg, $ s_html, $ a_gd_match );