PDA

View Full Version : Filtering out HTML using PHP ?



jvv
December 16th, 2000, 12:41
I'm writing a newsarticle script for my site, and I want to receive articles from users, but I don't want them to use html.

Does anyone know of a way to take the input from a form and then filter out the html ?

jvv
December 16th, 2000, 13:02
Never mind, I already found it myself. I'll post the code here so anyone else can also benefit from it




function strip_html ($text = "")
{
if( (!$text) or (empty($text)) )
{
return "";
}
$outside = true;
$rawText = "";
$length = strlen($text);
$count = 0;

for($count=0; $count < $length; $count++)
{
$digit = substr($text,$count,1);
if(!empty($digit))
{
if( ($outside) and ($digit != "<") and ($digit != ">") )
{
$rawText .= $digit;
}
if($digit == "<")
{
$outside = false;
}
if($digit == ">")
{
$outside = true;
}
}
}
return $rawText;
}

razor
December 16th, 2000, 14:44
just use this to filter out html:

$text = htmlspecialchars($text, ENT_QUOTES);