开发者

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜