- mb_convert_encoding: documentation ( source)
- preg_replace_callback: documentation ( source)
- pack: documentation ( source)
- json_encode: documentation ( source)
<?php
$name = "test";
$contact = "Test Contact";
$email = "test@testing.comm";
$phone = "12345678";
$obj = new stdClass();
$obj->id = "5f4e3913035190c04f69e83de9798019";
$obj->Type = "0";
$obj->Name = $name;
$obj->Contact = $contact;
$obj->Email = $email;
$obj->Phone = $phone;
$obj->Cellular = $phone;
$obj->Address = "הרחוב שלי 23";
$obj->City = "תל אביב";
$obj->Zip = "11233";
$obj->Comments = "הערות יתקבלו בברכה";
$obj2 = new stdClass();
$obj2->NewAccount = $obj;
function json_encode_unicode($data) {
return preg_replace_callback('/(?<!\\\\)\\\\u([0-9a-f]{4})/i',
function ($m) {
$d = pack("H*", $m[1]);
$r = mb_convert_encoding($d, "UTF8", "UTF-16BE");
return $r!=="?" && $r!=="" ? $r : $m[0];
}, json_encode($data)
);
}
$data = json_encode_unicode($obj2);