Home >Backend Development >PHP Tutorial >Positive expressions match attribute values of html tags
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
$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.