Javascript JS到PHP Foreach数组
通过Curl,我可以从js中的站点提取数据 下面是PHP中的代码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
$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);