Re: htmlentities()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Ronald Wiplinger wrote:
I tried to understand htmlentities by putting this code into a test.php:

<?php
if(!$page) {
?>
<H3>Test of evil input</H3>

<form method="post" action="<?php echo $PHP_SELF?>">

<INPUT type="text" name="field1" size="100" maxlength="100">
<INPUT type="hidden" name="page" value="1">
<INPUT type="submit" name="submit" value="Check it!">
</form>

<?php
}
else
{
echo "field1=$field1<br>";
$field2=htmlentities($field1,ENT_QUOTES,UTF-8);
echo "field2=$field2<p>";

you are echo'ing the same field1 variable as before.
by your comments at the bottom of what you expected the output
to be, I think you are wanting to use the $field2 variable instead.
echo htmlentities($field1,ENT_QUOTES,UTF-8);

echo "<p>";
$str = "A 'quote' is <b>bold</b>";

// Outputs: A 'quote' is &lt;b&gt;bold&lt;/b&gt;
echo htmlentities($str);
echo "<br>";
// Outputs: A &#039;quote&#039; is &lt;b&gt;bold&lt;/b&gt;
echo htmlentities($str, ENT_QUOTES);

}
?>



The output on the screen is:

field1=*Greater input and lower input*
field2=<b>Greater input and lower input</b>

<b>Greater input and lower input</b>

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


I expected that it would give me in the second line:
field2=&lt;b&gt;Greater input and lower input&lt;/b&gt;

and the lower two lines I expected as:

A 'quote' is &lt;b&gt;bold&lt;/b&gt;
A &#039;quote&#039; is &lt;b&gt;bold&lt;/b&gt;

are you viewing this in the html source or in the browser window?



What do I miss understand here?

bye

Ronald



--
Jim Lucas


    "Perseverance is not a long race;
        it is many short races one after the other"

Walter Elliot



    "Some men are born to greatness, some achieve greatness,
        and some have greatness thrust upon them."

Twelfth Night, Act II, Scene V
    by William Shakespeare

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux