我正在使用 cURL 开发小型网站抓取工具。
我决定使用 preg_match 来查找标题和文章内容。
这是我的代码:
preg_match('@<h2 class="title">(.*?)</h2>@s', $this->website, $this->title);
if(sizeof($this->title) > 1)
$this->title = trim($this->title[1]); // rewrite first element of array to regular variable
我正在试验它,我发现,如果有一个匹配 - 它在索引 1 的数组中返回它,而不是 0。
编辑问题:为什么这是 1,而不是 0?我做错了什么?
我的服务器:Apache/2.4.3 (Win32) PHP/5.4.7