# 帝国cms如何调用newstext正文字段所有img图片

*Published:* 2023-10-31
*Author:* 客服001

#### 温馨提醒

如果文章内容或图片资源失效，请留言反馈，我们会及时处理，谢谢

本文最后更新于2023年11月9日，已超过 180天没有更新



利用正则提取包含img的标签方法，然后再循环打印出来。

```
<?php
$<a class="tag_link" href="https://www.xarjtc.com/tag/newstext" target="_blank" title="查看newstext此标签更多文章"><abbr title="">newstext</abbr></a> = stripcslashes($navinfor['newstext']);   //正文newstext数据
preg_match_all('/<img.*?src="(.*?)".*?>/is', $newstext, $ImgArr);   //正则提取正文<a class="tag_link" href="https://www.xarjtc.com/tag/pic" target="_blank" title="查看图片此标签更多文章"><abbr title="">图片</abbr></a>
$ImgArr = array_unique($ImgArr[1]); //图片如有复生将去重复
$Imgno = 0; //给定初始序号
foreach ($ImgArr as $v) {   //判断有多少张图
    $Imgno ++;   //循环输出每一张图
?>
<img src="<?=$v?>" alt="<?=$navinfor['title'] ?>第<?=$Imgno ?>张"></a>    //输出的图片样式格式
<?php
}
?>
```