Jump to content

[SOLVED] PHP Allow HTML Only?


Stalingrad

Recommended Posts

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. =]

Link to comment
https://forums.phpfreaks.com/topic/132627-solved-php-allow-html-only/
Share on other sites

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

 

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>
?>

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

$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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.