Accents not working

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
noobnuggets
Forum Newbie
Posts: 5
Joined: Mon Mar 15, 2004 10:15 am

Accents not working

Post by noobnuggets »

Hello, I am getting some screwy behavior from some code I wrote.

Part of my php prints an error message directly to the html code. THe only issue is that the error message is in spanish and does not display correctly.

THe message is: "Número de calcomanía es requerido"

When I look at the page using mozilla firefox I see the following:
"N�mero de calcoman�a es requerido"
And if I view the source I see: "N�mero de calcoman�a es requerido"

When I look at the page in IE, I see: "N? de calcoman� es requerido"
And if i view the source I see: "Número de calcomanía es requerido"

Does anyone know what is causing this weirdness? I can see spanish language websites without issue in both browsers.

I am using the following code to output the message:

Code: Select all

$message = "Número de calcomanía  es requerido";
I am using the heredoc syntax to output the message to the page:

Code: Select all

$xml_version = "<?xml version="1.0" encoding="iso-8859-1"?".">"; 
$html_code = <<<EOF
$xml_version
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>$title</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
//Excess code omitted
$message<br/>
$code
</center>
</body>
</html>	
EOF;

echo $html_code;
TheBentinel.com
Forum Contributor
Posts: 282
Joined: Wed Mar 10, 2004 1:52 pm
Location: Columbus, Ohio

Re: Accents not working

Post by TheBentinel.com »

noobnuggets wrote:$html_code = <<<EOF
...
</html>
EOF;
I think it's the here document that's killing you, but I can't figure out why. I took it out and it seemed happy. Could you rework it without it, maybe split your PHP code into a couple of blocks and let the HTML just exist in the page?

here documents are picky little monsters, I just don't think they're worth the trouble of using them. (On this, I'm sure there is much disagreement. Just my flawed opinion.)
noobnuggets
Forum Newbie
Posts: 5
Joined: Mon Mar 15, 2004 10:15 am

Post by noobnuggets »

OOOOHHH :(

Removing that would mean reworking the entire app. The thing that gets me is why is the html source different when I do view source in different browsers? What is happening there?
Deemo
Forum Contributor
Posts: 418
Joined: Sun Jan 18, 2004 11:48 am
Location: Washington DC

Post by Deemo »

is there a char() function in php like in C++? then you could just put in the ascii value
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

Hmm, try [php_man]chr[/php_man]. That's all I could find regarding converting ASCII to characters.
TheBentinel.com
Forum Contributor
Posts: 282
Joined: Wed Mar 10, 2004 1:52 pm
Location: Columbus, Ohio

Post by TheBentinel.com »

noobnuggets wrote:OOOOHHH :(

Removing that would mean reworking the entire app. The thing that gets me is why is the html source different when I do view source in different browsers? What is happening there?
I completely misunderstood your problem, entirely my fault, sorry.

I think you want to convert those accented characters to their equivalent html entities. Here's a table of them:

http://www.htmlhelp.com/reference/html4 ... atin1.html

The source and output looks different because the various browsers and source viewers handle those characters differently. When you convert them to the entities, each browser should render them correctly.

Hope it helps, and sorry for the confusion!

(But I still hate here docs!!! ;-) )
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

Perhaps also interesting:
[php_man]get_html_translation_table[/php_man](), [php_man]htmlspecialchars[/php_man](), [php_man]htmlentities[/php_man]() ...to mention some.
noobnuggets
Forum Newbie
Posts: 5
Joined: Mon Mar 15, 2004 10:15 am

Post by noobnuggets »

I would like to thank you guys for all the responses to my post. I am going to try and apply the fixes you have given me, and then I will let everybody know if I got it to work.

Thanks!

Also if you guys could direct me to more debate about using heredoc I am interested in learning more. This is my very first php app, so I know there is a lot of stuff I still need to learn.[/php_man]
noobnuggets
Forum Newbie
Posts: 5
Joined: Mon Mar 15, 2004 10:15 am

Post by noobnuggets »

A big thank you to all of you! I used the html reference to solve my problem:
I think you want to convert those accented characters to their equivalent html entities. Here's a table of them:

http://www.htmlhelp.com/reference/html4 ... atin1.html
Thanks!
Post Reply