This question already has an answer here:
So I'm trying to prepend a <br>
tag in front of the longest word encountered in a given string in PHP. The strings I'm working with may also contain characters from various languages, but all the strings are encoded in UTF-8.
// Here I'm prepending a <br> tag before the longest word in $words which is a subset of $string
substr_replace($string, "<br>", strpos($string , $words[$longest]) - 1, 0);
But I've noticed that when I modify a string of Korean or Russian text with this line of code, a U+FFFD character gets inserted, even replacing some characters in the string. Would anyone have a clue as to why that occurs?
Thanks
</div>
Check out this built in function nl2br [ http://php.net/manual/en/function.nl2br.php ]
its un-defined character in the set [ https://en.wikipedia.org/wiki/Specials_(Unicode_block) ] so its kinda like null.
I would base64_encode [ http://php.net/manual/en/function.base64-encode.php ] before storing and base64_decode [http://php.net/manual/en/function.base64-decode.php] before serving the data.
Alternatively you can try utf8_encode [ http://us2.php.net/manual/en/function.utf8-encode.php ] and utf8_decode [ http://us2.php.net/manual/en/function.utf8-decode.php ]
Also UTF-8 Character set ( https://en.wikipedia.org/wiki/UTF-8 )