Jump to content

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

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.

 

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

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.