$pattern = '/"url":\s*"(.*?)"/';
$string = 'let player = new HlsJsPlayer({"id": "mse","isLive": true,"playsinline": true,"whitelist": [""],"url": "https://news.cgtn.com/resource/live/document/cgtn-doc.m3u8","autoplay": true,"volume": 0.8,"fluid": true,"pip": true,"closeVideoTouch": true});';

preg_match($pattern, $string, $matches);

$url = $matches[1]; // 'https://news.cgtn.com/resource/live/document/cgtn-doc.m3u8'

// 去掉引号
$url = trim($url, ''');

echo $url; // https://news.cgtn.com/resource/live/document/cgtn-doc.m3u8

本文展示了如何使用PHP正则表达式从HlsJsPlayer配置对象中提取URL。代码使用preg_match函数匹配字符串,并将URL提取到$matches数组中。最后使用trim函数去掉引号,得到最终的URL。

PHP正则表达式提取HlsJsPlayer中的URL

原文地址: http://www.cveoy.top/t/topic/odW4 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录