How can I best trim the following text outside the braces:
$myString = "10:0{ 'name':'John', 'age':30, 'car':null }24:0";
The text outside of the braces 10:0
and 24:0
may vary.
How can I best trim the following text outside the braces:
$myString = "10:0{ 'name':'John', 'age':30, 'car':null }24:0";
The text outside of the braces 10:0
and 24:0
may vary.
You can trim
numbers and colons off with:
trim($myString, '0123456789:');
... or you could replace everything outside the braces:
preg_replace('/.*?(\{.*?\}).*/', '$1', $myString);
Just grab what's inside the braces:
preg_match('/{[^}]+}/', $myString, $match);
echo $match[0];