Stalingrad Posted November 13, 2008 Share Posted November 13, 2008 Hello! I'm working on the profile page for my website, and I m having a little trouble. I want to be able to allow users to use HTML on their user lookups, and only HTML. (Well, and normal text, if they don't use HTML). How do I allow them to do so? Right now I'm using the strip_tags() function, but It strips the HTML tags too, which I don't want. Is there any wya to allow this? Any help is greatly appreciated. Thanks in advance. =] Quote Link to comment https://forums.phpfreaks.com/topic/132627-solved-php-allow-html-only/ Share on other sites More sharing options...
DeanWhitehouse Posted November 13, 2008 Share Posted November 13, 2008 http://uk3.php.net/manual/en/function.strip-tags.php Read it then you will understand you can do it with strip_tags(); by using the second argument. Quote Link to comment https://forums.phpfreaks.com/topic/132627-solved-php-allow-html-only/#findComment-689665 Share on other sites More sharing options...
Stalingrad Posted November 13, 2008 Author Share Posted November 13, 2008 Thank you. But what do you mean the second arguement? May you please show me what the second arguement is and how to use it? Thanks. =] Quote Link to comment https://forums.phpfreaks.com/topic/132627-solved-php-allow-html-only/#findComment-689670 Share on other sites More sharing options...
Mark Baker Posted November 13, 2008 Share Posted November 13, 2008 Thank you. But what do you mean the second arguement? May you please show me what the second arguement is and how to use it? Thanks. =] From the very top of the page that you've been pointed to: string strip_tags ( string $str [, string $allowable_tags ] ) $allowable_tags is the second argument... to find examples of its use, read that page Quote Link to comment https://forums.phpfreaks.com/topic/132627-solved-php-allow-html-only/#findComment-689677 Share on other sites More sharing options...
Stalingrad Posted November 13, 2008 Author Share Posted November 13, 2008 Oh, okay. Thanks. So if I have the following variable $ui_lookup, how would I put the strip_tags and the $allowable_tags? Quote Link to comment https://forums.phpfreaks.com/topic/132627-solved-php-allow-html-only/#findComment-689679 Share on other sites More sharing options...
DeanWhitehouse Posted November 13, 2008 Share Posted November 13, 2008 Did you look at the link? <?php $arr = array( "<html>", "<body>", "</body>", "</html>" ); $var = strip_tags("<html><body><a href="#">example</a></body></html>",$arr); echo $var;//should output <html><body><a href="#">example</></body></html> ?> Quote Link to comment https://forums.phpfreaks.com/topic/132627-solved-php-allow-html-only/#findComment-689684 Share on other sites More sharing options...
Stalingrad Posted November 13, 2008 Author Share Posted November 13, 2008 Thanks. I'm not understanding that though. Quote Link to comment https://forums.phpfreaks.com/topic/132627-solved-php-allow-html-only/#findComment-689691 Share on other sites More sharing options...
Mchl Posted November 13, 2008 Share Posted November 13, 2008 Second argument for strip_tags is string not an array. You have to put in it all tags, that you want NOT to strip. $stripped = strip_tags($toBeStripped,"<a><p><b><i><img>"); // this will allow <a> <p> <b> <i> and <img> tags and strip all others Quote Link to comment https://forums.phpfreaks.com/topic/132627-solved-php-allow-html-only/#findComment-689698 Share on other sites More sharing options...
DeanWhitehouse Posted November 13, 2008 Share Posted November 13, 2008 It will allow any tags that are in the array, but a warning i would not allow any tags that can have javascript elements, e.g. <a href="#" onClick="alert('you have been hacked');">Hacked</a> As this can really mess up your site. Quote Link to comment https://forums.phpfreaks.com/topic/132627-solved-php-allow-html-only/#findComment-689700 Share on other sites More sharing options...
Stalingrad Posted November 13, 2008 Author Share Posted November 13, 2008 Thank You. One more question: what is the $tobestripped variable supposed to be, and what is the $stripped variable supposed to be, and what do I put to echo the $ui_lookup with the strip_tags and stuff? Quote Link to comment https://forums.phpfreaks.com/topic/132627-solved-php-allow-html-only/#findComment-689708 Share on other sites More sharing options...
Mchl Posted November 13, 2008 Share Posted November 13, 2008 $toBeStripped is the text from which you want to remove html tags (so in your case this is what user puts in their profile), and $stripped is same text after html tags are removed. These are just examples, and you should put your variable names instead. Quote Link to comment https://forums.phpfreaks.com/topic/132627-solved-php-allow-html-only/#findComment-689714 Share on other sites More sharing options...
DeanWhitehouse Posted November 13, 2008 Share Posted November 13, 2008 are you joking? $tobestripped // guess what it should be maybe the variable that is to be stripped $stripped // again guess, if you don't what it is then go and learn php We are showing the means of doing it, not writing it for you. Quote Link to comment https://forums.phpfreaks.com/topic/132627-solved-php-allow-html-only/#findComment-689715 Share on other sites More sharing options...
Stalingrad Posted November 13, 2008 Author Share Posted November 13, 2008 Thanks so much! =D Quote Link to comment https://forums.phpfreaks.com/topic/132627-solved-php-allow-html-only/#findComment-689720 Share on other sites More sharing options...
Stalingrad Posted November 13, 2008 Author Share Posted November 13, 2008 Blade - I wasn't asking you to write it for me. I was just confused, as the strip_tags() function is new to me. Sorry for the double-post. Quote Link to comment https://forums.phpfreaks.com/topic/132627-solved-php-allow-html-only/#findComment-689723 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.