PDA

View Full Version : PHP does not show special characters


Rocko
07-03-2008, 04:01 PM
Hi,

Please help me to solve this special characters problem using PHP (php-5.1.6-3.el4s1.9):

Code:
<html>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=UTF-8'>
</head>
<body>
<?php print"áàäâa" ?>
</body>
</html>

Output:


Note how it is a single block, neither the "a" is showed.

I tried also:

<?php
header(Content-Type: application/html; charset=UTF-8)
print"áàäâa"
?>

But the browsers ask for an application to open the result.

Kind Regards,

Rocko

barkermn01
07-03-2008, 04:06 PM
this is HTML

HTML can not display special characters like that you have to use the HTML Code or use
htmlentities();

E.G

<?php
header(Content-Type: application/html; charset=UTF-8)
$values = htmlentities("áàäâa");
print $values
?>


if you are wanting to change from HTML code back to special characters
Use this

html_entity_decode();

Mwnciau
07-03-2008, 04:07 PM
UTF-8 doesn't support those kind of characters, you'd need to use a different character encoding (like below). The content-type of HTML pages is text/html not application/html which is why it was probably causing problems.

<?php
header(Content-Type: text/html; charset=ISO-8859-1);
echo "бадвa";
?>

barkermn01
07-03-2008, 04:11 PM
UTF-8 doesn't support those kind of characters, you'd need to use a different character encoding (like below). The content-type of HTML pages is text/html not application/html which is why it was probably causing problems.

<?php
header(Content-Type: text/html; charset=ISO-8859-1);
echo "бадвa";
?>

This would work also but i prefer php convertion to HTML chars it safer

Rocko
07-03-2008, 06:54 PM
Thank you.

Both options worked fine:

<?php
$values = htmlentities("áàäâa");
print $values
?>
<?php
header("Content-Type: text/html; charset=ISO-8859-1");
echo "áàäâa";
?>

But now I got the doubt about using or not UTF-8 as here is described:
CodingForums.com > :: Client side development > XML
Why using UTF-8?

barkermn01
07-03-2008, 10:59 PM
if you are using php dont send a header
unless you are using langs like japaneis (sorry for spelling)
you dont need to UTF-8 is the standerd HTML encoding you can use ANCI but not with php codes that use headers coz ANCI sends hiden text and there for a header is sent