Removing tags

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
fluidbyte
Forum Commoner
Posts: 30
Joined: Tue May 27, 2008 2:07 pm

Removing tags

Post by fluidbyte »

I'm new to php and I'm working on an inline content manager. I've got a WYSIWYG editor, but when I pass it through (post) I'm wanting to remove any link tags (<link href="whatever.css" />) as well as any <style>[CONTENTS]</style> tags.

I know regular expressions is probably the way to go, but I can't seem to get it figured out. Any help would be greatly appreciated.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: Removing tags

Post by Benjamin »

Do you need all tags removed or only specific tags?

strip_tags may work for you: http://us3.php.net/manual/en/function.strip-tags.php

Otherwise you may want to take a look at htmlpurifier: http://htmlpurifier.org/

I've never used that so I don't know if it will work for you but I do believe you can pass it a list of approved tags.

Your next option is to parse them out with regex.
fluidbyte
Forum Commoner
Posts: 30
Joined: Tue May 27, 2008 2:07 pm

Re: Removing tags

Post by fluidbyte »

I want to let the user apply almost any onther tags (including in-line styles). I just don't want them to be able to attach a stylesheet, or create an internal ss.
Post Reply