Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/402.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript JS到PHP Foreach数组_Javascript_Php_Foreach - Fatal编程技术网

Javascript JS到PHP Foreach数组

Javascript JS到PHP Foreach数组,javascript,php,foreach,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-hovr

通过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链接。

是否保证“
var locations=
”为常量前缀?然后,将其删除并将其余部分解码为JSON就相当简单了……”var locations=“可以通过str_replaceOK删除,那么您就差不多准备好了,不是吗?这里有一个正则表达式方法:或者可以通过提取内部链接来完成”
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);