phputf-8utf8mb4urdu

How to convert variable (text/string) to utf8mb4 in php


Hi I'm looking for a encode function for utf8mb4,

$var = = "نور";

echo utf8mb4_encode($string);

output = نور // its $var output in UTFMB4

The output should be "نور" this, its a conversion of $var in utfmb4


Solution

  • The return value of the mb_convert_encoding function could give you the desired result.

    $string = "نور";
    $result = mb_convert_encoding($string, 'UTF-8', 'Windows-1252');
    //$result = mb_convert_encoding($string, 'UTF-8', 'Windows-1254');
    echo $result;