Forum Moderators: coopster

Message Too Old, No Replies

htmlentities

         

jarea

6:51 am on Mar 11, 2005 (gmt 0)

10+ Year Member



This seems terribly simple but I cannot get it to work. The htmlentities and htmlspecialchars functions do not appear to be converting the special characters that are thrown at them.

<?
$str = "A 'quote' is <b>bold</b>";
$output = htmlentities($str, ENT_QUOTES);
$output1 = htmlentities($str, ENT_NOQUOTES);
$output2 = htmlentities($str, ENT_COMPAT);
$output3 = htmlentities($str);
echo "output is $output<br>output1 is $output1<br>output2 is $output2<br>output3 is $output3<br><br>";

$output = htmlspecialchars($str, ENT_QUOTES);
$output1 = htmlspecialchars($str, ENT_NOQUOTES);
$output2 = htmlspecialchars($str, ENT_COMPAT);
$output3 = htmlspecialchars($str);
echo "output is $output<br>output1 is $output1<br>output2 is $output2<br>output3 is $output3<br>";

>?

Produces:

output is A 'quote' is <b>bold</b>
output1 is A 'quote' is <b>bold</b>
output2 is A 'quote' is <b>bold</b>
output3 is A 'quote' is <b>bold</b>

output is A 'quote' is <b>bold</b>
output1 is A 'quote' is <b>bold</b>
output2 is A 'quote' is <b>bold</b>
output3 is A 'quote' is <b>bold</b>

Can anyone explain what is going on here?

Thanks - Jim

dreamcatcher

9:09 am on Mar 11, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



jarea, welcome to WebmasterWorld. :)

Have you looked at your source code? The character entities will display the characters correctly on your web page, but in your source code they will still be character entities.

Just a thought. Alternatively, if all you want to convert are apostrophes, try str_replace().

dc

jarea

4:19 pm on Mar 11, 2005 (gmt 0)

10+ Year Member



That's it. Thanks - Jim