magarlick Posted June 23, 2009 Share Posted June 23, 2009 Hi all. I have an odd problem with accented letters becoming garbled. Consider this snippet (I have the charset set to UTF-8 in the meta content of this document): <?php $foo = 'étoile'; echo $foo; ?> The above works fine. The text is printed with the accent intact. But now look at this. First, a modification to the above (again, same charset): <?php include 'set_variable.php'; echo $foo; ?> And this is what's in set_variable.php: <?php $foo = 'étoile'; ?> If I do it like this, then the accented e in the variable $foo is garbled. A lozenge with a question mark. I have no idea why. I cannot pass any strings with accented characters in them. They all come out garbled. I looked in the php.ini file and set default_charset = "utf-8". Same. So I cut it out completely. Same. So I set default_charset = "iso-8859-1". Still garbled but not a lozenge this time. I looked in the httpd.conf and added this: #AddCharset UTF-8 .utf8 #AddDefaultCharset UTF-8 Same. The problem just will not go away. Does anybody have any idea how to fix this? Thanks for any input. Mark I use Vista Home Premium, PHP 5.2.9-2, Apache 2.2.11. note: use can use tags Link to comment https://forums.phpfreaks.com/topic/163408-text-with-accents-garbled-after-using-includ/ Share on other sites More sharing options...
celsoendo Posted June 24, 2009 Share Posted June 24, 2009 Maybe your set_variable.php file is saved with incorrect encoding (different from the encoding of the main file). Link to comment https://forums.phpfreaks.com/topic/163408-text-with-accents-garbled-after-using-includ/#findComment-862407 Share on other sites More sharing options...
magarlick Posted June 24, 2009 Author Share Posted June 24, 2009 Thank you, celsoendo. How do I set the encoding then when saving a php file? I use Dreamweaver CS3. I have not actively set any encoding for my PHP files, except those that have an HTML header in them. So I do not see why some would have one encoding, and others would have another. Cheers. M. Link to comment https://forums.phpfreaks.com/topic/163408-text-with-accents-garbled-after-using-includ/#findComment-862498 Share on other sites More sharing options...
celsoendo Posted June 25, 2009 Share Posted June 25, 2009 Hi. I don't know how to config dreamweaver cause I never used it, but here is the result of my tests: set_variable.php <?php $foo = 'étoile'; $foo2 = 'étoile'; ?> main.php <?php include 'set_variable.php'; echo $foo . '<br />'; echo $foo2 . '<br />'; ?> Ok. The code above printed out $foo with wrong characters and $foo2 with accents. Changed main.php to: <?php include 'set_variable.php'; header('Content-type: text/html; charset=utf-8'); echo $foo . '<br />'; echo $foo2 . '<br />'; ?> And it worked with $foo and $foo2. Cheers Link to comment https://forums.phpfreaks.com/topic/163408-text-with-accents-garbled-after-using-includ/#findComment-863053 Share on other sites More sharing options...
magarlick Posted June 25, 2009 Author Share Posted June 25, 2009 Thanks again for replying. Yes I tried including that header statement before but it had no effect. In fact I have solved the problem: the included file was corrupt, although it looked perfectly normal. I created a blank php file, copied the contents of the old include_variable.php into it, then saved as include_variable.php, overwriting the original file. It worked right away. Who knows why these things are necessary! I appreciate your help. Mark. Link to comment https://forums.phpfreaks.com/topic/163408-text-with-accents-garbled-after-using-includ/#findComment-863253 Share on other sites More sharing options...
celsoendo Posted June 26, 2009 Share Posted June 26, 2009 Hi! I think these strange things is Dreamweaver's errors! Just an opinion, cause I really hate Dreamweaver.... lol! You should use a PHP IDE for php programming and forget Dreamweaver... Topic resolved! Link to comment https://forums.phpfreaks.com/topic/163408-text-with-accents-garbled-after-using-includ/#findComment-863914 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.