I have this string
{"CALL CENTER":"CALL CENTER"}
I need to print CALL CENTER
and I have tried using
substr($mystring, strpos($mystring, ":") + 1)
It gives me "CALL CENTER"}
How can I remove the special character from the result?
I have this string
{"CALL CENTER":"CALL CENTER"}
I need to print CALL CENTER
and I have tried using
substr($mystring, strpos($mystring, ":") + 1)
It gives me "CALL CENTER"}
How can I remove the special character from the result?
Use json_decode with the assoc array flag set to true and then you can just access the data in the array instead of parsing the string yourself.
$jsonArray = json_decode('{"CALL CENTER":"CALL CENTER"}', true);
echo $jsonArray['CALL CENTER']; // CALL CENTER
$jsonArray = json_decode('{"CALL CENTER":"CALL CENTER 2"}', true);
echo $jsonArray['CALL CENTER']; // CALL CENTER 2
http://sandbox.onlinephpfunctions.com/code/7650e1b9e705318e31c2b02f44ed05f9ee201d13
You can use the trim()
function:
$mystring = trim($mystring, '"}');
Documentation: http://php.net/manual/en/function.trim.php