How do I check if a string contains HTML?
It also depends how robust you want your check to be.
A simple way would be to test for the presence of < or > in the string - this does not guarantee it is HTML but often works if you just want a cursory check.
Another method would be to call strip_tags on the code and then check how that length measures up against the code without that function being called, a little like this:
<?php
$actual_length = strlen($isithtml);
$stripped_length = strlen(strip_tags($isithtml));
if($actual_length != $stripped_length) {
echo "The length has changed when we call strip tags, therefore the string does contain HTML";
}
else { echo "HTML? What HTML? None to be seen here!"; }
?>
Comment on this Question and Answer >>>
ASK A QUESTION
More strings PHP Questions
How do I find the ASCII value of a string character?How do I convert characters to HTML entities using PHP?
How do I make the contents of a string lower case?
How do I convert relevant characters in a string to HTML entities?
How do I count the number of words in my text?
