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 break email address into username and hostname?What is the difference between ' and "?
How do I replace a word in a string in PHP?
How do I convert characters to HTML entities using PHP?
How do you hash the password in this php script: define(sb db user name, admin store); define(sb db password, mypassword);
