How to get a part of a string from MySQL?
I have this table row
id | text
1 | {"category_layout":"","image":"images\/icon-48-info.png"}
How can I get only the image path from the text inside the brackets?
What I need is only this: images/icon-48-info.png (Note that there are 2 sla开发者_C百科shes in the text \ / while I need only one /
EDIT: Actually it is very simple, and I found a nice solution:
$json = $row->text;
$obj = json_decode($json);
echo $obj->{'image'};
No need for regexp or anything else.
Read the string functions reference, try it using the Regexp or Substring_index
Actually it is very simple, and I found a nice solution:
$json = $row->text;
$obj = json_decode($json);
echo $obj->{'image'};?>
精彩评论