Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Old 07-03-2008, 05:01 PM   PM User | #1
Rocko
New Coder

 
Join Date: Feb 2007
Posts: 36
Thanks: 7
Thanked 0 Times in 0 Posts
Rocko has a little shameless behaviour in the past
PHP does not show special characters

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
Rocko is offline   Reply With Quote
Old 07-03-2008, 05:06 PM   PM User | #2
barkermn01
Regular Coder

 
Join Date: Nov 2007
Location: Leeds, UK
Posts: 455
Thanks: 16
Thanked 15 Times in 15 Posts
barkermn01 can only hope to improve
this is HTML

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

E.G
PHP Code:
<?php
header
(Content-Typeapplication/htmlcharset=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();
barkermn01 is offline   Reply With Quote
Users who have thanked barkermn01 for this post:
Rocko (07-03-2008)
Old 07-03-2008, 05:07 PM   PM User | #3
Mwnciau
Regular Coder

 
Join Date: May 2006
Location: Wales
Posts: 806
Thanks: 1
Thanked 77 Times in 74 Posts
Mwnciau is on a distinguished road
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 Code:
<?php
 header
(Content-Typetext/htmlcharset=ISO-8859-1);
 echo 
"áàäâa";
?>
Mwnciau is offline   Reply With Quote
Users who have thanked Mwnciau for this post:
Rocko (07-03-2008)
Old 07-03-2008, 05:11 PM   PM User | #4
barkermn01
Regular Coder

 
Join Date: Nov 2007
Location: Leeds, UK
Posts: 455
Thanks: 16
Thanked 15 Times in 15 Posts
barkermn01 can only hope to improve
Quote:
Originally Posted by Mwnciau View Post
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 Code:
<?php
 header
(Content-Typetext/htmlcharset=ISO-8859-1);
 echo 
"áàäâa";
?>
This would work also but i prefer php convertion to HTML chars it safer
barkermn01 is offline   Reply With Quote
Old 07-03-2008, 07:54 PM   PM User | #5
Rocko
New Coder

 
Join Date: Feb 2007
Posts: 36
Thanks: 7
Thanked 0 Times in 0 Posts
Rocko has a little shameless behaviour in the past
Thank you.

Both options worked fine:

PHP Code:
<?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?
Rocko is offline   Reply With Quote
Old 07-03-2008, 11:59 PM   PM User | #6
barkermn01
Regular Coder

 
Join Date: Nov 2007
Location: Leeds, UK
Posts: 455
Thanks: 16
Thanked 15 Times in 15 Posts
barkermn01 can only hope to improve
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
barkermn01 is offline   Reply With Quote
Users who have thanked barkermn01 for this post:
Rocko (07-04-2008)
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:36 PM.

Home - Contact Us - Archives - Link to CF - Resources - Top 

Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.