UTF + French characters
Moderator: General Moderators
UTF + French characters
I am in a rut and I can't get out of it, I've spent all weekend (and most of my Football Sunday) trying to figure out this problem. I have done numerous research, but still nothing.
If you check out this linkhttp://www.mtl-baseline.com/fr/accueil.php
You can see that the french characters are not being displayed properly. I have this in my <head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
The reason i need to use utf-8 and not iso-8859-1 (which would display the characters) is because it would show me weird characters before the song title of the TOP 40 radio that is on my site (which is an include from a radio streaming site). (So it's either having utf-8 but no french characters or having iso-8859-1 bt the weird characters)
i.e --> utf-8 http://www.mtl-baseline.com/fr/accueil.php
iso-8859-1 --> http://www.mtl-baseline.com/fr/accueil2.php
So please, does anybody have any ideas as to fix this....
Thank you
P.S. I wont get back in front of my computer until late tonite so I wont be able to reply right away.
Thank you to those who will read this
If you check out this linkhttp://www.mtl-baseline.com/fr/accueil.php
You can see that the french characters are not being displayed properly. I have this in my <head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
The reason i need to use utf-8 and not iso-8859-1 (which would display the characters) is because it would show me weird characters before the song title of the TOP 40 radio that is on my site (which is an include from a radio streaming site). (So it's either having utf-8 but no french characters or having iso-8859-1 bt the weird characters)
i.e --> utf-8 http://www.mtl-baseline.com/fr/accueil.php
iso-8859-1 --> http://www.mtl-baseline.com/fr/accueil2.php
So please, does anybody have any ideas as to fix this....
Thank you
P.S. I wont get back in front of my computer until late tonite so I wont be able to reply right away.
Thank you to those who will read this
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
in 'Français' ç is output as a character.. It is outside the range of "normal" ascii, so is considered an escape character in UTF.. the easy way around it is to convert ç to the correct HTML entity: ç
using [php_man]htmlentities()[/php_man] on the content of these "weird character" boxes should convert them to usable forms.
using [php_man]htmlentities()[/php_man] on the content of these "weird character" boxes should convert them to usable forms.
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
as I said, the content..
Code: Select all
<?php
function specialEntityEncode($data)
{
if(sizeof($data) == 3)
{
return htmlentities($dataї1]);
}
else
{
return $dataї3] . htmlentities($dataї7]);
}
}
$text = 'Français<test />Français<a href="blah > asdf" test =
quickie jump>Français< table>';
echo preg_replace_callback('#(^(ї^<]*)?|(<\\s*?їa-z]+\\s*?(їa-z]+?\\s*(=\\s*(ї"'']?).*?\\\\6)?\\s*)*?\\s*/?\\s*>)(ї^<]*))#is','specialEntityEncode', $text);
?>Code: Select all
Fran&ccedil;ais<test />Fran&ccedil;ais<a href="blah > asdf" test =
quickie jump>Fran&ccedil;ais< table>- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
no, you don't have to preprocess the content, although that can save time if the page is accessed quite often.
The snippet I wrote can be used to preprocess the content, or just-in-time process it on demand. Just need to be careful if you have entities (instead of the ascii character) in your content.
The snippet I wrote can be used to preprocess the content, or just-in-time process it on demand. Just need to be careful if you have entities (instead of the ascii character) in your content.
ok...now i'm getting another problem.... i modified your code to suit my site
(just the $text was changed)
that works great but when I put it again for another file it gives me this error
Fatal error: Cannot redeclare specialentityencode() (previously declared in /home/mtlbase/public_html/fr/accueil.php:228) in /home/mtlbase/public_html/fr/nouvelles_index.php on line 20
which is pretty straight forwared...i can't put your snippet of code twice on the same page......so how to I make the $text have multiple values?
Code: Select all
<?php
function specialEntityEncode($data) {
if(sizeof($data) == 3) {
return htmlentities($data[1]);
}else{
return $data[3] . htmlentities($data[7]);
}
}
$text = ''.substr($row_nouvelles['text'],0, 275).'...'.'';
echo preg_replace_callback('#(^([^<]*)?|(<\s*?[a-z]+\s*?([a-z]+?\s*(=\s*(["'']?).*?\\6)?\s*)*?\s*/?\s*>)([^<]*))#is','specialEntityEncode', $text);
?>that works great but when I put it again for another file it gives me this error
Fatal error: Cannot redeclare specialentityencode() (previously declared in /home/mtlbase/public_html/fr/accueil.php:228) in /home/mtlbase/public_html/fr/nouvelles_index.php on line 20
which is pretty straight forwared...i can't put your snippet of code twice on the same page......so how to I make the $text have multiple values?