Page 1 of 1
htmlenitities() html_entity_decode()
Posted: Fri Dec 03, 2010 8:43 am
by amirbwb
hi everyone, i am creting a comment box so i want users to be allowed to insert symbols like : ♥♣♠• but in the the same time i don't want to get a field box when they insert <input type="text">
for example if they entered this --> hello ♥ <input type="text">
the result :
-with nl2br(htmlentities())
hello � <input type="text">
-withoutit or with nl2br(html_entity_decode())
hello ♥ [_____________________] (with a field where i can write)
I hope u understand the prob
thanks for helping

Re: htmlenitities() html_entity_decode()
Posted: Fri Dec 03, 2010 12:11 pm
by social_experiment
htmlspecialchars() ?
(sic) php manual
The translations performed are:
'&' (ampersand) becomes '&'
'"' (double quote) becomes '"' when ENT_NOQUOTES is not set.
''' (single quote) becomes ''' only when ENT_QUOTES is set.
'<' (less than) becomes '<'
'>' (greater than) becomes '>'
Re: htmlenitities() html_entity_decode()
Posted: Tue Aug 16, 2011 5:08 am
by amirbwb
if i use htmlspecialchars()
it gives me:
<input> & #9829; (I have added the space between "
&#...;" because the page is transforming the code into symbole)
what i want is <input> ♥
here is my code for testing:
Code: Select all
<?php
$a=$_POST['a'];
?>
<form method="post">
<input name="a" value="<?php echo $_POST['a'];?>">
</form>
<?php
echo htmlspecialchars($a);
?>
Re: htmlenitities() html_entity_decode()
Posted: Tue Aug 16, 2011 11:17 am
by social_experiment
strip_tags() is an option. It removes html and php tags but you have an option to allow certain tags. This should leave the symbols displaying as symbols. You could also use a function like str_replace to replace all html-unsafe characters and replace them with html-safe characters.
Re: htmlenitities() html_entity_decode()
Posted: Tue Aug 16, 2011 11:51 am
by phphelpme
I think the best option here would be strip_tags()
http://php.net/manual/en/function.strip-tags.php
Best wishes
Re: htmlenitities() html_entity_decode()
Posted: Wed Aug 17, 2011 12:58 pm
by amirbwb
mmm ok ... but I'll have lot of code to add .. anw thks both of u =)