Tycho01 Posted April 24, 2010 Share Posted April 24, 2010 I'm trying to use a multi-byte string replacement function with some Japanese in my script, but it's failing due to one of the strings being compared being stuck in ASCII. The script itself is saved as UTF-8. $text = iconv('ASCII', 'UTF-8', $text); //$text = utf8_encode($text); echo "Encoding: ".mb_detect_encoding($text); I've tried either of the two methods above, but regardless of which I pick, it still echoes 'Encoding: ASCII'. I'm pretty new to this, so I'm probably missing something here, but is there any obvious reason why both of these might fail? Thanks! Link to comment https://forums.phpfreaks.com/topic/199617-ascii-string-wont-convert-to-utf-8/ Share on other sites More sharing options...
Tycho01 Posted April 25, 2010 Author Share Posted April 25, 2010 Additional info: I tried getting some more info on the strings and their encoding, results as follows: needle: よく needle encoding: UTF-8 foo encoding: ASCII bar encoding: UTF-8 position needle in foo: position needle in bar:25203 ^ foo is in ascii, and the position function fails. I know for a fact the info in foo hasn't gone lost though, as it's able to display its contents fine. After trying to utf8_decode everything hoping it'd work: needle: ?? needle encoding: ASCII foo encoding: ASCII bar encoding: ASCII position needle in foo: position needle in bar:275 ^ not the desired effect, and now it feels like the first bit of Japanese it encounters is 'close enough' to the needle. tl;dr: converting from UTF-8 to ASCII using iconv/utf8_decode works for me, but not the other way around. :/ Link to comment https://forums.phpfreaks.com/topic/199617-ascii-string-wont-convert-to-utf-8/#findComment-1047920 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.