使用 Php 如何获得 Javascript Object 值

Using Php how to get Javascript Object Value

它的 javascript 来自另一个网站的代码 变种图像= { article_id : '1111', 频道:'$11111', image_license : 'https://website.com/test', 名称:“数字” }

使用Php 如何获取图片的值_license ( https://website.com/test )

我的想法是我制作了一个文章抓取器,它可以从 html 获取标题、描述等,但是我无法从 js 代码中获取这个值,那该怎么办呢?

尝试使用正则表达式:

preg_match("/image_license\s*:\s*'(.*?)'/",$html,$result);
$image_license_url = $result[1];

另一个例子:

preg_match("/var images = (\{.*?\})/",$html,$result);
$images_array = json_decode($result[1]);

参考:https://www.php.net/manual/en/function.preg-match.php