Home >Backend Development >PHP Problem >What should I do if the php regular expression cannot be matched?
Solution to the problem that php cannot match the regular pattern: 1. Use the preg_match_all() function to obtain the regular matching content; 2. Output the matching content through print_r.
The operating environment of this article: Windows7 system, PHP7.1 version, DELL G3 computer
Specific questions:
php正则匹配不到 <?php $url = "http://music.sogou.com/sogou_phb/coo/music/getCampMeta2.jsp?cate=randomsong&count=100&jsoncallback=jsonp1373432530259"; $text = file_get_contents($url); //正则创建 preg_match("/title\":\"(.*?)\"/", $text, $w); //echo $text; echo $w ?> 为什么我这个一个也匹配不到呢?
Solution:
1. To obtain the content matched by the regular expression, you should use the preg_match_all() function
2. It is an array. Arrays cannot be output using echo. If echo outputs an array, it will only display Array
<?php $url = " http://music.sogou.com/sogou_phb/coo/music/getCampMeta2.jsp?cate=randomsong&count=100&jsoncallback=jsonp1373432530259 "; $text = file_get_contents($url); //正则创建 preg_match_all("/title\":\"(.*?)\"/", $text, $w); //echo $text; print_r($w); ?>
. Recommended study: "PHP Video Tutorial"
The above is the detailed content of What should I do if the php regular expression cannot be matched?. For more information, please follow other related articles on the PHP Chinese website!