使用preg_match从html源检索数据

时间:2015-05-25 15:48:56

标签: php regex preg-match

请查看以下源代码

LMS.pageData['product']['thumbnails'].push({
                            zoomUrl: 'http://07fcfb85ff11d7f5d0fc-f4c51c056b0940e95f0098eed18ef033.r99.cf3.rackcdn.com/4403569-SPLSPR15MJKT-SPORT-A2-SSP15_01-800.jpg',
                            url: 'http://07fcfb85ff11d7f5d0fc-f4c51c056b0940e95f0098eed18ef033.r99.cf3.rackcdn.com/4403569-SPLSPR15MJKT-SPORT-A2-SSP15_01-480.jpg',
                            smallUrl: 'http://07fcfb85ff11d7f5d0fc-f4c51c056b0940e95f0098eed18ef033.r99.cf3.rackcdn.com/4403569-SPLSPR15MJKT-SPORT-A2-SSP15_01-110.jpg'
                        });

                        LMS.pageData['product']['thumbnails'].push({
                            zoomUrl: 'http://07fcfb85ff11d7f5d0fc-f4c51c056b0940e95f0098eed18ef033.r99.cf3.rackcdn.com/4403569-SPLSPR15MJKT-SPORT-A2-SSP15_02-800.jpg',
                            url: 'http://07fcfb85ff11d7f5d0fc-f4c51c056b0940e95f0098eed18ef033.r99.cf3.rackcdn.com/4403569-SPLSPR15MJKT-SPORT-A2-SSP15_02-480.jpg',
                            smallUrl: 'http://07fcfb85ff11d7f5d0fc-f4c51c056b0940e95f0098eed18ef033.r99.cf3.rackcdn.com/4403569-SPLSPR15MJKT-SPORT-A2-SSP15_02-110.jpg'
                        });

                        LMS.pageData['product']['thumbnails'].push({
                            zoomUrl: 'http://07fcfb85ff11d7f5d0fc-f4c51c056b0940e95f0098eed18ef033.r99.cf3.rackcdn.com/4403569-SPLSPR15MJKT-SPORT-A2-SSP15_03-800.jpg',
                            url: 'http://07fcfb85ff11d7f5d0fc-f4c51c056b0940e95f0098eed18ef033.r99.cf3.rackcdn.com/4403569-SPLSPR15MJKT-SPORT-A2-SSP15_03-480.jpg',
                            smallUrl: 'http://07fcfb85ff11d7f5d0fc-f4c51c056b0940e95f0098eed18ef033.r99.cf3.rackcdn.com/4403569-SPLSPR15MJKT-SPORT-A2-SSP15_03-110.jpg'
                        });

                        LMS.pageData['product']['thumbnails'].push({
                            zoomUrl: 'http://07fcfb85ff11d7f5d0fc-f4c51c056b0940e95f0098eed18ef033.r99.cf3.rackcdn.com/4403569-SPLSPR15MJKT-SPORT-A2-SSP15_04-800.jpg',
                            url: 'http://07fcfb85ff11d7f5d0fc-f4c51c056b0940e95f0098eed18ef033.r99.cf3.rackcdn.com/4403569-SPLSPR15MJKT-SPORT-A2-SSP15_04-480.jpg',
                            smallUrl: 'http://07fcfb85ff11d7f5d0fc-f4c51c056b0940e95f0098eed18ef033.r99.cf3.rackcdn.com/4403569-SPLSPR15MJKT-SPORT-A2-SSP15_04-110.jpg'
                        });

                        LMS.pageData['product']['thumbnails'].push({
                            zoomUrl: 'http://07fcfb85ff11d7f5d0fc-f4c51c056b0940e95f0098eed18ef033.r99.cf3.rackcdn.com/4403569-SPLSPR15MJKT-SPORT-A2-SSP15_05-800.jpg',
                            url: 'http://07fcfb85ff11d7f5d0fc-f4c51c056b0940e95f0098eed18ef033.r99.cf3.rackcdn.com/4403569-SPLSPR15MJKT-SPORT-A2-SSP15_05-480.jpg',
                            smallUrl: 'http://07fcfb85ff11d7f5d0fc-f4c51c056b0940e95f0098eed18ef033.r99.cf3.rackcdn.com/4403569-SPLSPR15MJKT-SPORT-A2-SSP15_05-110.jpg'
                        });

我需要检索zoomUrl的值,如上面的示例代码所示,我们有5个zoomUrl。

谢谢!

1 个答案:

答案 0 :(得分:0)

尝试:

preg_match_all('(zoomUrl: \'(.+?)\')', $html, $matches);
print_r($matches);

这应该创建一个这样的输出:

Array
(
    [0] => Array
        (
            [0] => zoomUrl: 'http://07fcfb85ff11d7f5d0fc-f4c51c056b0940e95f0098eed18ef033.r99.cf3.rackcdn.com/4403569-SPLSPR15MJKT-SPORT-A2-SSP15_01-800.jpg'
            [1] => zoomUrl: 'http://07fcfb85ff11d7f5d0fc-f4c51c056b0940e95f0098eed18ef033.r99.cf3.rackcdn.com/4403569-SPLSPR15MJKT-SPORT-A2-SSP15_02-800.jpg'
            [2] => zoomUrl: 'http://07fcfb85ff11d7f5d0fc-f4c51c056b0940e95f0098eed18ef033.r99.cf3.rackcdn.com/4403569-SPLSPR15MJKT-SPORT-A2-SSP15_03-800.jpg'
            [3] => zoomUrl: 'http://07fcfb85ff11d7f5d0fc-f4c51c056b0940e95f0098eed18ef033.r99.cf3.rackcdn.com/4403569-SPLSPR15MJKT-SPORT-A2-SSP15_04-800.jpg'
            [4] => zoomUrl: 'http://07fcfb85ff11d7f5d0fc-f4c51c056b0940e95f0098eed18ef033.r99.cf3.rackcdn.com/4403569-SPLSPR15MJKT-SPORT-A2-SSP15_05-800.jpg'
        )

    [1] => Array
        (
            [0] => http://07fcfb85ff11d7f5d0fc-f4c51c056b0940e95f0098eed18ef033.r99.cf3.rackcdn.com/4403569-SPLSPR15MJKT-SPORT-A2-SSP15_01-800.jpg
            [1] => http://07fcfb85ff11d7f5d0fc-f4c51c056b0940e95f0098eed18ef033.r99.cf3.rackcdn.com/4403569-SPLSPR15MJKT-SPORT-A2-SSP15_02-800.jpg
            [2] => http://07fcfb85ff11d7f5d0fc-f4c51c056b0940e95f0098eed18ef033.r99.cf3.rackcdn.com/4403569-SPLSPR15MJKT-SPORT-A2-SSP15_03-800.jpg
            [3] => http://07fcfb85ff11d7f5d0fc-f4c51c056b0940e95f0098eed18ef033.r99.cf3.rackcdn.com/4403569-SPLSPR15MJKT-SPORT-A2-SSP15_04-800.jpg
            [4] => http://07fcfb85ff11d7f5d0fc-f4c51c056b0940e95f0098eed18ef033.r99.cf3.rackcdn.com/4403569-SPLSPR15MJKT-SPORT-A2-SSP15_05-800.jpg
        )

)

演示:https://eval.in/369655