• Howdy! Welcome to our community of more than 130.000 members devoted to web hosting. This is a great place to get special offers from web hosts and post your own requests or ads. To start posting sign up here. Cheers! /Peo, FreeWebSpace.net
managed wordpress hosting

Filtering out HTML using PHP ?

jvv

New Member
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 ?
 
Never mind, I already found it myself. I'll post the code here so anyone else can also benefit from it

Code:
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;
	}
 
Back
Top