Connecting Tech Pros Worldwide Help | Site Map

htmlentities is not working for me

jl
Guest
 
Posts: n/a
#1: Aug 26 '06
>From the php manual I copied and pasted this example:

<?php
$str = "A 'quote' is <b>bold</b>";

// Outputs: A 'quote' is &lt;b&gt;bold&lt;/b&gt;
echo htmlentities($str);

// Outputs: A 'quote' is &lt;b&gt;bold&lt;/b&gt;
echo htmlentities($str, ENT_QUOTES);
?>

However, when I run it in my browser, the output is wrong:

A 'quote' is <b>bold</b>A 'quote' is <b>bold</b>

the < is not converted to &lt (no conversion is taking place)

Is there a configuration that would disable htmlentities?
Does anyone have any idea as to what would cause htmlentities to not
work?

Thanks!
jl

jl
Guest
 
Posts: n/a
#2: Aug 26 '06

re: htmlentities is not working for me



jl wrote:
Quote:
Quote:
From the php manual I copied and pasted this example:
>
<?php
$str = "A 'quote' is <b>bold</b>";
>
// Outputs: A 'quote' is &lt;b&gt;bold&lt;/b&gt;
echo htmlentities($str);
>
// Outputs: A 'quote' is &lt;b&gt;bold&lt;/b&gt;
echo htmlentities($str, ENT_QUOTES);
?>
>
However, when I run it in my browser, the output is wrong:
>
A 'quote' is <b>bold</b>A 'quote' is <b>bold</b>
>
the < is not converted to &lt (no conversion is taking place)
>
Is there a configuration that would disable htmlentities?
Does anyone have any idea as to what would cause htmlentities to not
work?
>
Thanks!
jl
I figured it out. The browser was reconverting the string.

Rik
Guest
 
Posts: n/a
#3: Aug 26 '06

re: htmlentities is not working for me


jl wrote:
Quote:
jl wrote:
Quote:
Quote:
>>From the php manual I copied and pasted this example:
>>
><?php
>$str = "A 'quote' is <b>bold</b>";
>>
>// Outputs: A 'quote' is &lt;b&gt;bold&lt;/b&gt;
>echo htmlentities($str);
>>
>// Outputs: A 'quote' is &lt;b&gt;bold&lt;/b&gt;
>echo htmlentities($str, ENT_QUOTES);
Quote:
>>>
>>
>However, when I run it in my browser, the output is wrong:
>>
>A 'quote' is <b>bold</b>A 'quote' is <b>bold</b>
>>
>the < is not converted to &lt (no conversion is taking place)
>>
>Is there a configuration that would disable htmlentities?
>Does anyone have any idea as to what would cause htmlentities to not
>work?
>>
>Thanks!
>jl
>
I figured it out. The browser was reconverting the string.
Not exactly. The browser was interpreting it as the aplicable characters
instead of HTML tags, which is what it is used for.

If you want to display &lt;, you'll have to have &amp;lt; in yout code.

--
Rik Wasmus


Alvaro G. Vicario
Guest
 
Posts: n/a
#4: Aug 26 '06

re: htmlentities is not working for me


*** jl escribió/wrote (26 Aug 2006 07:19:53 -0700):
Quote:
I figured it out. The browser was reconverting the string.
The browser is not actually altering the string. You need to use the
"View-Source code" menu.

--
-+ http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
++ Mi sitio sobre programación web: http://bits.demogracia.com
+- Mi web de humor con rayos UVA: http://www.demogracia.com
--
Closed Thread