Page 1 of 1

function htmlentities()

Posted: Sat Jun 30, 2007 2:16 am
by php-linux
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hi,
I work with a ubuntu system and php 5.2.1.
The next code doesn't convert special characters and html codes to entities!

Code: Select all

<html>
<head>
<title>Text including html</title>
</head>

<body>
<?php
echo phpinfo();
$str= <<<TEXT
Einstürzende Neubauten and Marya's & <br>Mother and again "test".
TEXT;
$code=htmlentities($str, ENT_QUOTES);
$code1=htmlspecialchars($str);
echo $code,"<br>",$code1;
?>
</body>

</html>
The output of the code is:
Einstürzende Neubauten and Marya's & <br>Mother and again "test".
Einstürzende Neubauten and Marya's & <br>Mother and again "test".
Could you tell me why my code doesn't work?

Thanks,


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Sat Jun 30, 2007 2:47 am
by miro_igov
If you read carefully what htmlentities() do you will not ask that dummy question: http://php.net/htmlentities

htmlentities() replaces your < and > to < and > which makes them looking < and > in the browser. Note that you see <BR>, but don't see the line break exactly.

Posted: Sat Jun 30, 2007 3:02 am
by php-linux
You'r right! :lol: