Home >Backend Development >PHP Tutorial >javascript - next quotation mark problem after php regular match

javascript - next quotation mark problem after php regular match

WBOY
WBOYOriginal
2016-08-04 09:21:091027browse

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

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>

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

Statement:
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