[thelist] html stripping

Chris Rosser chris at bluefuton.com
Thu Apr 29 09:07:55 CDT 2004


> I am trying to strip all links from any given web sites.I want to do that
> with regular expression but i don't know how i can do that. At first i
> thought, i can do this with such a
> preg_match_all("'<a.*href.*>.*</a>'",$html,$links); but it doesn't do
> anything. I added strip_tags above this,
> strip_tags($html,"<a>");
> but it didn't help much too.

You don't need to use preg_match_all - strip_tags will do the link
stripping for you, if you use the right syntax :)

Try:

$html = strip_tags($html);

The second argument in strip_tags is for 'allowable' tags, i.e. tags that
will *not* be stripped. For example, if you wanted to strip out everything
*except* <a> tags, you could use:

strip_tags($html,'<a>');

See:

http://www.php.net/strip_tags

Hope this helps!

Chris
}:)




More information about the thelist mailing list