javascript - next quotation mark problem after php regular match

WBOY
Release: 2016-08-04 09:21:09
Original
992 people have browsed it

<code>$html = <<<EOF
<a href="a.php?u=ABjhpIVC;b=5" onmousedown="return rwt(AFQjCNH3RnE94GMEJkoxp0Iy1fSbpjbbwQ)">title</a>
EOF;

$isMatched = preg_match('/<a(.*?)href="(.*?)">(.*?)<\/a>/', $html, $matches);</code>
Copy after login
Copy after login

I used this code to finally match the content from to
">title
The final output result
a.php?u=ABjhpIVC;b=5" onmousedown="return rwt (AFQjCNH3RnE94GMEJkoxp0Iy1fSbpjbbwQ)
I want to get the content between the first double quotation mark and the second quotation mark, which is the content of the a tag href=
I don’t need to get the content from the first quotation mark to the last double quotation mark, please ask How can I modify this code to match it?

Reply content:

<code>$html = <<<EOF
<a href="a.php?u=ABjhpIVC;b=5" onmousedown="return rwt(AFQjCNH3RnE94GMEJkoxp0Iy1fSbpjbbwQ)">title</a>
EOF;

$isMatched = preg_match('/<a(.*?)href="(.*?)">(.*?)<\/a>/', $html, $matches);</code>
Copy after login
Copy after login

I used this code to finally match the content from to
">title
The final output result
a.php?u=ABjhpIVC;b=5" onmousedown="return rwt (AFQjCNH3RnE94GMEJkoxp0Iy1fSbpjbbwQ)
I want to get the content between the first double quotation mark and the second quotation mark, which is the content of the a tag href=
I don’t need to get the content from the first quotation mark to the last double quotation mark, please ask How can I modify this code to match it?

Then you have to use greedy matching~
/<a(.*?)href="(.*)">(.*?)</a>/
You use .*? is followed by " and he will stop as long as he matches the next character "

Using forbidden greedy matching U
Personal experience, when you write the regular expression, always add Uis

'/(.*)/iU', there are attributes after href, don’t write the ones that can’t be matched

Related labels:
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!