|
-
Feb 6th, 2008, 05:52 PM
#1
Thread Starter
Addicted Member
[RESOLVED] search replace help
I am trying to remove specific HTML tags from from text. I am currently working with the str_ireplace but it is starting to get cumbersome because there are so many ways to write the same tag. This is what I have now
PHP Code:
$search=array('<p>','</p>','</ p>','<p/>','<p />','<br>','</br>','</ br>','<br/>','<br />');
$replace=array('','','','','','','','','','');
and that is only two of the tags I want to remove. By the time I am done this line will be a mile long.
I tried reading the pattern rules to preg_replace but something unexpected happened, my head detached from my neck and hit the floor. 
There must be a simpler way. (using a case-insensitive function is a bonus )
Changes are not permanent, but change is. {Neil Peart}
-
Feb 6th, 2008, 06:39 PM
#2
Re: search replace help
You would have to use regular expressions.
http://www.regular-expressions.info/php.html
I suck with regex so I wont be much help on the subject I'm afraid.
Also, if there is XML in the code, it could cause issues as well.
-
Feb 6th, 2008, 09:22 PM
#3
Re: search replace help
Use the strip_tags function. You can pass an array of tags to allow and the rest will be removed.
Last edited by penagate; Feb 6th, 2008 at 09:36 PM.
-
Feb 6th, 2008, 09:25 PM
#4
Re: search replace help
I had no idea that function existed, but you linked incorrectly pena.
http://ca3.php.net/manual/en/function.strip-tags.php
-
Feb 6th, 2008, 09:36 PM
#5
Re: search replace help
Thanks, I fixed the link.
-
Feb 8th, 2008, 10:54 AM
#6
Thread Starter
Addicted Member
Re: search replace help
Works like a charm. Thanks penagate. This is why I love PHP. It seems that they have a function for everything.
Changes are not permanent, but change is. {Neil Peart}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|