html - Detect CSS class in a page and write if/else in PHP -
i have page need detect css class , apply if/else statement using php. how do that?
html
<body> <div class="insights"> hello world </div> </body>
what php code detect , find "insights" class exists , show "yes, exists". if there's no class of name show "no, doesn't exists."
how should achieve this?
a simple solution use strpos
$contains = str($html, 'class="insights"') !== false;
a more complex , robust solution be, use regular expression following
class="[^"]*\binsights\b[^"]*"
this used in php this
$contains = (bool) preg_match('/class="[^"]*\binsights\b[^"]*"/', $html);
Comments
Post a Comment