/    Sign up×
Community /Pin to ProfileBookmark

Htmlentities() trouble

Hi

I’ve problem with the function htmlentities it prints “A ‘quote’ is <b>bold</b&gtA ‘quote’ is <b>bold</b&gt” when it should print
” A ‘quote’ is <b>bold</b&gt” and “A ‘quote’ is <b>bold</b&gt” what am I doing wrong?

Here is the code example

<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN” “http://www.w3.org/TR/html4/loose.dtd“>
<html>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=iso-8859-1″>
<title>Untitled Document</title>
</head>

<body>
<?php
$str = “A ‘quote’ is <b>bold</b>”;
//$str = “A ‘quote’ is &lt;b&gt;bold&lt;/b&gt”;

// 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);
?>
</body>
</html>

Hope anyone could help me

to post a comment
HTML

3 Comments(s)

Copy linkTweet thisAlerts:
@NogDogJul 21.2005 — [code=php]
// Outputs: A 'quote' is &lt;b&gt;bold&lt;/b&gt;
echo "<p>" . htmlentities($str) . "</p>n";

// Outputs: A 'quote' is &lt;b&gt;bold&lt;/b&gt;
echo "<p>" . htmlentities($str, ENT_QUOTES) . "</p>n";
[/code]
Copy linkTweet thisAlerts:
@mamboauthorJul 22.2005 — [code=php]
// Outputs: A 'quote' is &lt;b&gt;bold&lt;/b&gt;
echo "<p>" . htmlentities($str) . "</p>n";

// Outputs: A 'quote' is &lt;b&gt;bold&lt;/b&gt;
echo "<p>" . htmlentities($str, ENT_QUOTES) . "</p>n";
[/code]
[/QUOTE]


It still doesn't work, nothing happens. I could use

$str = preg_replace( '/'/', 'X', $str); that works but then you have to type in many lines of code. Do you have any other ideas?

Thanks for your help so far
Copy linkTweet thisAlerts:
@NogDogJul 22.2005 — Perhaps I'm not clear as to what the actual problem is? I thought you were complaining that it was all coming out on one line instead of 2, which I corrected. But now I'm thinking your saying the ENT_QUOTES parameter is not resulting in the quotes being encoded? If so, it's working fine for me when I cut and paste your code onto my PHP 4 installation.
×

Success!

Help @mambo spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...