davidannis Posted March 31, 2014 Share Posted March 31, 2014 I am trying to replace the last character in a Japanese word with another. substr_replace did not work - I figured because it was multibyte so I tried using only multibyte functions, but it is still not working. Here's the code I'm trying <meta charset="utf-8"> <?php $word='くたくた'; //substr_replace($word, 'ひ',-1); $length=mb_strlen ( $word); $length--; $word = mb_substr ( $word , $start ,$length).'ひ'; echo $word; ?> Which results in くたく��ひ I am probably just using the multi_byte functions wrong but can't see how. Quote Link to comment https://forums.phpfreaks.com/topic/287421-utf-8-character-replacement/ Share on other sites More sharing options...
Solution requinix Posted March 31, 2014 Solution Share Posted March 31, 2014 mbstring is the correct way but you have to make sure it knows what character encoding to use. mb_internal_encoding sets the "default" encoding. Otherwise pass the encoding to each of the mbstring functions. Quote Link to comment https://forums.phpfreaks.com/topic/287421-utf-8-character-replacement/#findComment-1474561 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.