PHP从字符串中刮取图像 - 如何?

时间:2012-01-07 00:59:54

标签: php scrape

我是一个PHP菜鸟... 无论如何 - 我如何从这个字符串中获取所有图像链接? (进入数组)

{                      "imagedata": {       "duration": 4000,       "images":{                "image1":{         "url":"/images/nature/flowers/pictureKUO133529A.jpeg",         "title":"",         "index":"01"         },         "image2":{         "url":"/images/nature/flowers/pic092533.jpg",         "title":"",         "index":"02"         },         "image3":{         "url":"/images/nature/flowers/pic092529.jpg",         "title":"",         "index":"03"         },         "image4":{         "url":"/images/nature/flowers/pic092531.jpg",         "title":"",         "index":"04"         },         "image5":{         "url":"/images/nature/flowers/pic092530.jpg",         "title":"",         "index":"05"         },         "image6":{         "url":"/images/nature/flowers/pic092534.jpg",         "title":"",         "index":"06"         },         "image7":{         "url":"/images/nature/flowers/0112678pic092532.jpg",         "title":"",         "index":"07"         },         "image8":{         "url":"/images/nature/flowers/0112881pic092656.jpg",         "title":"",         "index":"08"         },         "image9":{         "url":"/images/nature/flowers/0112880pic092655.jpg",         "title":"",         "index":"09"         }       }       }                     }

我尝试过preg_match_all()但我无法让它工作.... 我只想要像/images/nature/flowers/0112880pic092655.jpg

这样的字符串

btw我从脚本标签中删除了上述数​​据......

提前致谢

1 个答案:

答案 0 :(得分:4)

好吧,你可以使用正则表达式。但由于它似乎是JSON,对json_decode()的简单调用可能会这样做。

如果需要阵列结构,请将第二个参数设置为TRUE 然后访问它:

print $array["imagedata"]["images"]["image1"]["url"];