Home > Backend Development > PHP Problem > What should I do if the php regular expression cannot be matched?

What should I do if the php regular expression cannot be matched?

藏色散人
Release: 2023-03-09 19:30:01
Original
2338 people have browsed it

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.

What should I do if the php regular expression cannot be matched?

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
?>

为什么我这个一个也匹配不到呢?
Copy after login

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);
 
?>
Copy after login

. 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!

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template