How do i display the percent sign %
in PHP using unicode %
?
Here is the code开发者_运维百科.
echo $percent . "%";
I have the code inside a PHP function on a separate page it is then displayed on the HTML page.
Do you mean how to display it in HTML once echo()'d from PHP? Your code there should do it. I just tested it on jsbin (the HTML entity at least).
Judging by your comment,
The php code just displays 99 % for example.
Well, it should, of course, in the HTML. If your viewing that in the front of your browser, it would be likely your encoding htmlspecialchars()
or similar. But since you are echo'ing, that should be hard to capture and encode, unless using output buffer functions. Can you provide any more information please?
have you looked at the html source that's being output? does it say
99%
or
99%
or something similar?
Why are you using the entity? There's nothing wrong with
echo $percent . '%';
$var = $percent . "%";
echo str_replace('%', '%', $var); // POG :O
Try using the following: sprintf("99%%. Hopefull will echo out a percent sign!",$str,$number);
link text
Let me know if that works?
精彩评论