使用dom php从给定URL获取元素
使用php构建MTDB,需要从URL中刮取特定标记 要从url获取的标记使用dom php从给定URL获取元素,php,Php,使用php构建MTDB,需要从URL中刮取特定标记 要从url获取的标记 vars.disqus = ''; vars.lists = []; vars.titleId = '35079'; vars.trailersPlayer = 'default'; vars.userId = '907791'; vars.title = {"id":35079,"title":"Family Vacation","trailer":35097.flv,"t
vars.disqus = '';
vars.lists = [];
vars.titleId = '35079';
vars.trailersPlayer = 'default';
vars.userId = '907791';
vars.title = {"id":35079,"title":"Family Vacation","trailer":35097.flv,"timing":0.50sec}
我需要
"id":35079,"title":"Family Vacation","trailer":35097.flv,"timing":0.50sec
我的代码:
$html = 'myurl';
libxml_use_internal_errors(TRUE); $dom = new DOMDocument; $dom->loadHTMLFile($html); libxml_clear_errors();
$xp = new DOMXpath($dom); $nodes = $xp->query('//script[@\'id','trailer','title');
echo $nodes->item(0)->nodeValue;
preg_match('/title\s*=\s*\{([^}]+)}/', $str, $matches);
var_dump($matches[1]);
非常感谢。我可以在哪一行集成此代码?