PHP Questions Home | Register | Login
Categories
Arrays
Files
Forms
Creating PDFs
PHP Errors
Functions
Images
MySQL
Numbers
Others
Strings
Website
Unanswered

PHP Forums
Forums Index
MySQL Forum
PHP Forum
Flash/Actionscript
Javascript
Web design

More PHP
PHP Functions
Top Questions
Ask a Question
PHP Interview Questions
PHP Jobs
Ecommerce
IT Questions
Business Websites

Sponsors

sponsor ad
My Salary
PHP Developer Salary
Advertise Here

How do I check if a string contains HTML?


There are several ways that you can check whether a string contains HTML or not.

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);



Custom Search