function htmlentities()

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
php-linux
Forum Newbie
Posts: 2
Joined: Sat Jun 30, 2007 2:10 am

function htmlentities()

Post 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]
miro_igov
Forum Contributor
Posts: 485
Joined: Fri Mar 31, 2006 5:06 am
Location: Bulgaria

Post 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.
php-linux
Forum Newbie
Posts: 2
Joined: Sat Jun 30, 2007 2:10 am

Post by php-linux »

You'r right! :lol:
Post Reply