可能重复,以提取特定数据:
How to parse and process HTML with PHP?如何使用的preg_match()使用PHP
问题:
仅提取第一< UL类=”使用preg_match从网页列出“> </ul>并将其转储到数组中。
代码:
$str = file_get_contents('http://www.domain.com');
preg_match('#<ul class="list">(.*)</ul>#i', $str, $matches);
预期目标:
为了得到第< UL>和转储这一切在数组中。 < ul>应该是家长,里面的每个元素都应该是孩子。