-1

here is my json string { "opa": "O_\ufe0fP\ufe0f_\ufe0fA\ufe0f" }

when i decode my json string object(stdClass)#16 (1) { ["opa"]=> string(25) "O_ufe0fPufe0f_ufe0fAufe0f" }

i want to get without this ->\ufe0f symbols result should be "O_P_A"

P.S. it can be any other character like [\udbff, \udc00, etc.]

3
  • @Justinas unfortunately no Commented Feb 25, 2023 at 11:03
  • Show a complete example. Looks like the backslashes aren't escaped correctly. Commented Feb 25, 2023 at 11:06
  • Does this answer your question? stackoverflow.com/a/31689454 Commented Feb 25, 2023 at 11:36

1 Answer 1

0

Your string in the JSON contains 4 special Unicode characters Variation Selector-16 (VS16). With a special debug class, this string can be shown as a PHP-compliant string notation.

$jsonStr = '{ "opa": "O_\ufe0fP\ufe0f_\ufe0fA\ufe0f" }';
$obj = json_decode($jsonStr);
$stringWithVS16 = $obj->opa;

debug::writeUni($stringWithVS16); 
//string(17) UTF-8mb3 "O_\u{fe0f}P\u{fe0f}_\u{fe0f}A\u{fe0f}"

These special Unicode characters are real and this fact has nothing to do with the encoding or decoding of the JSON. If these signs bother you, all you have to do is remove them. In the simplest case, str_replace can do this.

$cleanString = str_replace("\u{fe0f}","",$stringWithVS16);
debug::writeUni($cleanString);
//string(5) ASCII "O_P_A" 

That's just a fix for that particular character. If other special characters bother you, you need to find a regular expression that removes all such characters with preg_replace.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.