I have a regex in the json data,
$config = '{"regex": "/font-size:\s*(?:.*);/i"}';
And I want to convert the json data to an array,
$config = json_decode($config,true);
var_dump($config);
It returns NULL due to the regex.
How can I get around to it?
So I can get this,
Array
(
[regex] => "/font-size:\s*(?:.*);/i"
)
is it possible?
edit:
it returns,
array(1) {
[0]=>
string(37) '{"regex": "/font-size:\s*(?:.*);/i"}'
}
should be…
array(1) {
["regex"]=>
string(22) "/font-size:\s*(?:.*);/i"
}
Your JSON has
JSON_ERROR_SYNTAXso you are having ErrosOption A You should use
stripslashesfirst but you would lose backslash\Output
Option B Create your own function
Output
Function Used (Only Splits to array)