Striping HTML and PHP tags from a $str

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
mykg4orce
Forum Newbie
Posts: 21
Joined: Tue May 28, 2002 2:19 pm

Striping HTML and PHP tags from a $str

Post by mykg4orce »

How do i do it... :) :)

lets say i have this:

Code: Select all

<?php
$str = "<i><b>Some Text Here</b></i>"
//I want it to return:
echo $str
//Some Text Here
?>
thanks in advance!!!!
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post by hob_goblin »

http://www.php.net/strip_tags

strip_tags() is your friend
mykg4orce
Forum Newbie
Posts: 21
Joined: Tue May 28, 2002 2:19 pm

Post by mykg4orce »

but i have tried it and it doesn't work. :(

Code: Select all

<?php
$string = "<b>MY STRING</b>";
$string = strip_tags($string, '<b></b>');
echo $string;

//this returns: <b>MY STRING</b> when i view source in my brower.
//thats not what i thought it would do, i thought it would just remove what i tell it to in the arguement.
//The reason i want to remove any HTML tags is so that when i 
//am using a script (Send To Friend) to send this string i 
//dont want the HMTL tags included in the email msg.
//Argh!!!!!
?>
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post by hob_goblin »

the second argument is the ALLOWED tags
mykg4orce
Forum Newbie
Posts: 21
Joined: Tue May 28, 2002 2:19 pm

Post by mykg4orce »

what do you mean????
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post by hob_goblin »

$string = "<b><u>Hi</u></b>";
$string_s = striptags($string, "<b>");
echo "$string_s";

would return

<b>Hi</b>

because the second paramater is the allowed tags, not the ones you want to strip, if you want to strip all tags, dont put a second paramater in, but if you want to exempt certain tags, put them there

if your trying to do this for security reasons; read the comments at:

http://www.php.net/manual/en/function.strip-tags.php

because some of them have very good points
mykg4orce
Forum Newbie
Posts: 21
Joined: Tue May 28, 2002 2:19 pm

Post by mykg4orce »

ohhhh wow!!!! what a dufus I am :) thanks!! man....
Post Reply