Home >Backend Development >PHP Tutorial >Positive expressions match attribute values ​​of html tags

Positive expressions match attribute values ​​of html tags

WBOY
WBOYOriginal
2016-07-29 09:02:03960browse

 Today, due to work requirements, I need to obtain the attribute value of the html tag. I immediately thought of regular expressions. The tag is as follows:




You need to obtain the cx and cy attribute values ​​of the tag , thought for a while and wrote one:

$circle is the content of the circle tag above

preg_match_all('/]*?cxs*=s*('|") (.*?)\1[^>]*?cys*=s*('|")(.*?)\1[^>]*?/?s*>/i', $circle , $arr);

var_dump($arr);

$arr[2] is the value of cx, $arr[4] is the value of cy.

<span><span><span><span><span><span><span><span><span><span><br></span></span></span></span></span></span></span></span></span></span>

The above introduces the positive value expression to match the attribute value of the html tag, including the content. I hope it will be helpful to friends who are interested in PHP tutorials.

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