[php-src] Issue #8768: str_replace vs utf8_decode

From: Date: Mon, 13 Jun 2022 19:59:37 +0000
Subject: [php-src] Issue #8768: str_replace vs utf8_decode
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-241720@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/8768 Author: MacDknife ### Description I cannot follow your normal way of reporting, because this is a weird error on two different OS:es. I have WAMP (ver, 3.2.3) in Windows 11 Pro Swe ,were I create my PHP scripts and then upload them to an Inleed server, that has Linux with a PHP version 7.4.29. My WAMP PHP version is 7.4.9. I have this function: function fixURL($Fix){ if ($Fix!==""){ $Swedish = array("å", "ä", "ö", "Å", "Ä", "Ö",); $SwedURL = array("Ã¥", "ä", "ö", "Ã…", "Ã,,", "Ã-"); $Fixed = str_replace($SwedURL, $Swedish, $Fix); return $Fixed; } } to convert UTF-8 characters to Swedish. It seemed to be working perfectly for a long time, both locally in WAMP and on the website (Inleed). Yesterday I noticed that all characters were converted except the capitals Ä and Ö. Only them - on the website! This still functioned in WAMP. During my attempts to find a solution, I found the utf8_decode() PHP function. This refused to function in the WAMP environment as a replacement for the function above, but when I tried it out on the website it worked like a charm! So now I have two verions of the same file, one for the website: function fixURL($Fix){ if ($Fix!=""){ $Fixed = utf8_decode($Fix); return $Fixed; } } and the other one with str_replace that I use locally, as shown above. All my files have <meta charset="ISO-8859-1">, where I have HTML in the script. I have ensured that all the script files are coded in ANSI, using Notepad ++. As I also have different htaccess files compared to Inleed, so I have attached them as well: [htaccess_WAMP.txt](https://github.com/php/php-src/files/8893801/htaccess_WAMP.txt) [htaccess_Inleed.txt](https://github.com/php/php-src/files/8893803/htaccess_Inleed.txt) They both only ensure that I have a ISO-8859-1 character set for my files. While trying to find a solution I tried with and without the htaccess files, changed from to ISO-8859-1 to UTF-8 in the PHP script files. The only thing that ensured Swedish characters on the web, was when I had the htaccess file activated. Which character set was activated did not seem to matter, while using the str_replace function. I did not experiment with the utf8_decode function. I was just too happy to see that it functioned! I know this is maybe not a big deal and maybe not even a bug, but I can't help feeling that both str_replace and utf8_decode functions should have quite similar internal functions and therefore both should be able to function in both environments! I could not find any similar reports on this issue. I also hope I have made enough sense in my explanation of the issue, but should I fail in that regard, please let me know. Both files are identical except for the conversion function mentioned above, but I would like to only have one version of my file. If you need the complete file let me know. If there are any other files (perhaps .ini) that you would like as well, or any thing else, please let me know. You can see this file in action on the front page of www.skglimma.se, where it randomly loads and displays fishing photos, using the file name as the basis for the text heading for the current photo. The utf8_decode (str_replace) function ensures that the heading here is correctly displayed with Swedish characters. Thanks in advance, /Errol ### PHP Version PHP 7.4.9 locally and 7.4.29 on website ### Operating System Windows 11 Pro Swe (22H2, ver. 22621.1) and Linux on website

« previous php.bugs (#241720) next »