Reputation: 579
I have some Unicode string in different languages like Arabic, Russian, etc.
I want to convert those Unicode string (جمع) to Unicode escape sequence (\u062c\u0645\u0639) using PHP.
Is there any function available for the same in PHP?
Upvotes: 0
Views: 717
Reputation: 96
mb_convert_encoding should work
like this:
$string = 'جمع';
$encodedString = mb_convert_encoding($string, 'UTF-16BE', 'UTF-8');
if you want to check the string for anything first, since PHP7 you can write unicode in double quoted or heredoc strings like this:
$unicodeString = "\u{062c}\u{0645}\u{0639}";
Upvotes: 1