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

Popular posts from this blog

php - Permission denied. Laravel linux server -

google bigquery - Delta between query execution time and Java query call to finish -

python - Pandas two dataframes multiplication? -