JS到PHP Foreach数组

时间:2017-07-28 10:15:35

标签: javascript php foreach

通过Curl,我可以从js中的网站中提取数据。

以下是PHP中的代码,

$content = 'var locations = ["https:\/\/website.to\/embed-h7jg2gopxi0k.html","https:\/\/website1.to\/embed-v3ywuokxeirq-580x326.html","https:\/\/website3.to\/embed-dzl49jlbx1lw.html","https:\/\/website2.to\/embed-hovrbjkng4cm.html];';

我如何将其转换为php和foreach链接。

1 个答案:

答案 0 :(得分:1)

if (preg_match('/\[(.*)\]/s', $content, $match)) {     // get the array part
    $string = str_replace(array('"', '\\'), "", $match[1]);     // remove " and escapes - \
    $your_desired_array = explode(',', $string);     // explode string on ,
}

print_r($your_desired_array);