Home >Backend Development >PHP Tutorial >Positive value expression matches the attribute value of html tag, expression attribute value_PHP tutorial
Today, due to work requirements, I need to obtain the attribute value of the html tag, and I immediately thought of regular expressions , the tags are as follows:
90b86670c4cbbcd6ac2dbda452b88c8d
< ;circle id="ap_test" cx="201" cy="2001" r="2" stroke="black" stroke-width="0" fill="red"/>
997b3342be6e183b5c976669bd986b2b
f7851bcda80b188a8fab988ec1963adc
I need to get the cx and cy attribute values of the dd8ccdce5934340a605ebf18ab3241ea tag. I thought for a while and wrote one:
$circle is the content of the circle tag above
preg_match_all('/386a0e0ab44031b4c6981a610c5bcfc1]*?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 id="line25"><span id="line26"><span id="line27"><span id="line28"><span id="line29"><span id="line30"><span id="line31"><span id="line32"><span id="line33"><span id="line34"><br /><br /></span></span></span></span></span></span></span></span></span></span>