Problems with characters in php

Problems with characters in php

Posted by: alberto666
Posted on: 2007-06-27 02:48:00

Hi everybody.

When I have a simple php file with something like this:

echo "español"

it prints in the screen:

"espa?ol"

the same with accents like áéíóú and other characters.

Do you know how to solve this?

I have this meta:
<meta content='text/html; charset=UTF-8' http-equiv='Content-Type'/>

in the HTML so I think that the problem is because other things...

In the server the files are fine, but when I execute the php it doesn't return the expected result.

Any idea about how to solve?

Re: Problems with characters in php

Posted by: Bats
Posted on: 2007-06-27 03:30:00

Easiest way is just to use the ascii code for it, try this one: ñ

JagaLaw

Re: Problems with characters in php

Posted by: alberto666
Posted on: 2007-06-27 03:43:00

I know, this is good & ntilde ;

but what about when I receive data from the user with no format?

And is really really weird, because I have a file with this code:
<?php
echo "áéñ";
?>

and for instance is I call this way:
file.php?id=4

It display fine, but if I call
file.php?id=2

is not fine, and there is no treatment at all of the parameters (as you can see, one line of code...).




Re: Problems with characters in php

Posted by: scjessey
Posted on: 2007-06-27 06:20:00

Use PHP to set the character encoding. Put this line at the beginning of each page:

<?php header("Content-Type: text/html; charset=utf-8"); ?>

You can also force all PHP files to be UTF-8 by default by adding this line to your .htaccess file:

AddCharset UTF-8 .php

--------
si-blog | Keystone Websites
Save $97 on yearly plans with promo code SCJESSEY97

Re: Problems with characters in php

Posted by: misterhaan
Posted on: 2007-06-27 08:09:00

are you sure your files are utf8? the default on windows systems is windows-1252

track7 - my dream-hosted site

Re: Problems with characters in php

Posted by: alberto666
Posted on: 2007-06-27 09:45:00

As you say, that was the problem, files were not in UTF-8 format. Now everything works fine.

And there were also a cache problem, when the browser saw a page in a specified format it always used it from that moment.

Thank you all ;)

Tags: php fileaccentsmetaprints