'json_encode fails because of Unknown charactar
I have this array :
[responses] => Array
(
[0] => Array
(
[date] => 2021-07-09 15:16:53
[text] => [Resume session��%
1 Yes
2 No, CANCEL, SEND]
)
)
[text] is taken from USSD response and it shows Resume session? on phone but inside the array it is Resume session��%. That's where json_encode fails.
How to fix that !?
Solution 1:[1]
This is old but I have (the/to) answer.
/** @var array $array the array from question above */
$encoded_array = json_encode($array ,JSON_INVALID_UTF8_IGNORE);
Note : This solution is PHP 7.2 and up .. It removes the invalid character.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Alaa Morad |
