帝国CMS新闻正文图片自动加alt与title为文章标题
- 自动给新闻正文图片添加ALT和TITLE属性:
- 将以下函数添加到
e/class/userfun.php
文件中:function user_AddImgAlt($mid, $f, $isadd, $isq, $value, $cs) { $title = $_POST['title']; $htmls = $value; $pattern = "/<img[^>]+>/"; preg_match_all($pattern, $htmls, $matches); for ($i = 0; $i <= count($matches[0]); $i++) { preg_match_all("/alt=\".+?\"/", $matches[0][$i], $altimg); preg_match_all("/title=\".+?\"/", $matches[0][$i], $titleimg); $t_alt = count($altimg[0]); if ($t_alt == 0) { $htmls = str_replace("<img", "<img alt=\"{$title}\"", $htmls); $htmls = str_replace("<img", "<img title=\"{$title}\"", $htmls); } } return $htmls; }
- 修改数据表中的新闻正文字段(如
newstext
),在字段处理函数文本框中填入user_AddImgAlt
。
- 将以下函数添加到
扫码添加技术【解决问题】
专注企业网站建设、网站安全16年。
承接:企业网站建设、网站修改、网站改版、BUG修复、问题处理、二次开发、PSD转HTML、网站被黑、网站漏洞修复等。
专业解决各种疑难杂症,您有任何网站问题都可联系我们技术人员。
本文来自博客园,作者:黄文Rex,转载请注明原文链接:https://www.cnblogs.com/hwrex/p/18510585