开发者

How to get a part of a string from MySQL?

开发者 https://www.devze.com 2023-03-04 21:30 出处:网络
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?

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'};?>
0

精彩评论

暂无评论...
验证码 换一张
取 消