帝国cms调用newstext正文字段所有img图片方法
2024-01-18
帝国cms模版的newstext字段是直接输出全部图文的,在需要单独调用newstext正文字段中的img图片时,就需要对newstext正文模块进行处理。
这里利用正则提取包含img的标签方法,然后再循环打印出来。
<?php
$newstext = stripcslashes($navinfor['newstext']); //正文newstext数据
preg_match_all('/<img.*?src=(.*?).*?>/is', $newstext, $ImgArr); //正则提取正文图片
$ImgArr = array_unique($ImgArr[1]); //图片如有复生将去重复
$Imgno = 0; //给定初始序号
foreach ($ImgArr as $v) { //判断有多少张图
$Imgno ++; //循环输出每一张图
?>
<img src=<?=$v?> alt=<?=$navinfor['title'] ?>第<?=$Imgno ?>张></a> //输出的图片样式格式
<?php
}
?> 声明:本文来自用户分享和网络收集,仅供学习与参考,测试请备份。