(Sorry if my english is bad, but is not my language)
In my PHP file I receive an object called $ orderdetalle that is generated in a part of the server where I do not have access and I don't know the encode of the server ...$ orderdetalle is an array that contains, in string fields, different values and between they the lastname. But if the lastname is for example, Hernández the variable keepsHern\u00e1ndez.
So that the lastname can later send it in a json, I am trying to do what I read in another similar question with str_replace() and preg_replace():
$lastname_consumer = $ordendetalle['customer_lastname'];//I receive the lastname Hern\u00e1ndez
$str_lastname = str_replace('\u','u',$lastname_consumer);
$lastname = preg_replace('/u([\da-fA-F]{4})/', '&#x\1;', $str_lastname);
$customer = array ( 'customer' => array ( 'id' => $ordendetalle['customerId'],
'lastname' => $lastname,
'firstname' => $ordendetalle['firstname'],
'email' => $ordendetalle['email']
)
);
$customer_order = print_r(json_encode($customer), true); //Print in a log
My problem is that $str_lastname gets Hern\u00e1ndez instead of Hernu00e1ndez when doing the str_replace(), and its worthless to subsequently do the preg_replace() and gets Hernández.
On the other hand, I have tried the code in http://phptester.net/ and it works perfectly for me but I understand that it is a matter of \u00e1 being a character UTF-8. So I do not know very well how to advance at this point.
Thanks for your time!
EDIT:
Add var_dump($ordendetalle):
["customer_id"]=> string(3) "979"
["customer_email"]=> string(23) "email@test.es"
["customer_firstname"]=> string(7) "UserTest"
["customer_lastname"]=> string(10) "Hernández"