PHP stristr false positive for CDATA -


the following html/css html email sent hotmail...

<style><!-- .hmmessage p { margin:0px; padding:0px } body.hmmessage { font-size: 12pt; font-family:calibri } --></style> 

i'm merely trying css inside style elements. may contain html comments such 1 above or cdata. strange reason php returning false-positive cdata below string above...

 if (stristr($b,'<style'))  {   $s = explode('<style',$b,2)[1];   $s = explode('>',$s,2)[1];    if (stristr($s,'<![cdata['))   {    $s = explode('<![cdata[',$s,2)[1];    $s = explode(']]',$s,2)[0];   }   else if (stristr($s,'<!--'))   {    $s = explode('<!--',$s,2)[1];    $s = explode('-->',$s,2)[0];   }   else   {    $s = explode('</style>',$s,2)[0];   } 

why not take domdocument?

$html = " <style><!-- .hmmessage p { margin:0px; padding:0px } body.hmmessage { font-size: 12pt; font-family:calibri } --></style>";   $dom = new domdocument(); $dom->loadhtml($html); $style = $dom->getelementsbytagname('style');  // content first style tag $css = $style->item(0)->nodevalue; // clear comments , cdata tags $css = str_replace(array('<!--', '-->', '<![cdata[', ']]>', '//<![cdata[', '//]]>'), '', $css); echo $css; 

Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

html - Unable to style the color of bullets in a list -

c# - must be a non-abstract type with a public parameterless constructor in redis -