<p class="cate">栏目1</p>
<p class="article-list">
<ul>
<li>
<a href="/article/110001.html">
<p class="article-img">
<img src="" src="/images/5.jpg" />
</p>
<p class="article-name">文章标题1</p>
</a>
</li>
<li>
<a href="/article/110021.html">
<p class="article-img">
<img src="" src="/images/51.jpg" />
</p>
<p class="article-name">文章标题2</p>
</a>
</li>
</ul>
</p>
<p class="cate">栏目2</p>
<p class="article-list">
<ul>
<li>
<a href="/article/130401.html">
<p class="article-img">
<img src="" src="/images/23.jpg" />
</p>
<p class="article-name">文章标题3</p>
</a>
</li>
<li>
<a href="/article/114022.html">
<p class="article-img">
<img src="" src="/images/26.jpg" />
</p>
<p class="article-name">文章标题4</p>
</a>
</li>
<li>
<a href="/article/123442.html">
<p class="article-img">
<img src="" src="/images/89.jpg" />
</p>
<p class="article-name">文章标题5</p>
</a>
</li>
<li>
<a href="/article/12225.html">
<p class="article-img">
<img src="" src="/images/42.jpg" />
</p>
<p class="article-name">文章标题6</p>
</a>
</li>
</ul>
</p>
.....此处省略相同的代码
看上面的代码.想通过preg_match_all获取一个多维数组(含栏目,文章)
想得类似结果如下:
array(
'栏目1'=>array(
array('/article/110001.html','/images/5.jpg','文章标题1'),
array('/article/110021.html','/images/51.jpg','文章标题2'),
),
'栏目2'=>array(
array('/article/130401.html','/images/23.jpg','文章标题3'),
array('/article/114022.html','/images/26.jpg','文章标题4'),
array('/article/123442.html','/images/89.jpg','文章标题5'),
array('/article/12225.html','/images/42.jpg','文章标题6'),
),
)
每个栏目下的文章数不固定.
谢谢了.
It cannot be achieved by using preg_match_all alone, but such arrays can be reassembled.
You can also use queryList, you will know it by Baidu.
It is recommended to use queryList. Your array cannot be implemented using regular expressions, but you can splice the arrays yourself after matching regular expressions
It’s a bit troublesome, but you can still get the results you want