Page 1 of 1

Accents not working

Posted: Wed Mar 17, 2004 2:54 pm
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;

Re: Accents not working

Posted: Wed Mar 17, 2004 3:13 pm
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.)

Posted: Wed Mar 17, 2004 3:52 pm
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?

Posted: Wed Mar 17, 2004 4:11 pm
by Deemo
is there a char() function in php like in C++? then you could just put in the ascii value

Posted: Wed Mar 17, 2004 4:39 pm
by pickle
Hmm, try [php_man]chr[/php_man]. That's all I could find regarding converting ASCII to characters.

Posted: Wed Mar 17, 2004 5:47 pm
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!!! ;-) )

Posted: Wed Mar 17, 2004 8:09 pm
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.

Posted: Thu Mar 18, 2004 9:10 am
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]

Posted: Thu Mar 18, 2004 9:34 am
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!