技术文摘

帝国cms后台发布内容自动把内容图片的alt和title替换为文章标题

作者:雨祺   发表于:
浏览:62次    字数:423  原创
级别:站长   总稿:81篇, 月稿:12
操作方法如下:
1.把下面的代码放到/e/class/userfun.php (放到最后?>的前面)
  1. function user_imgalt($mid,$f,$isadd,$isq,$value,$cs){ 
  2. $title=$_POST['title']; 
  3. $htmls=$value; 
  4. $pattern = "/<img[^>]+>/";  
  5. preg_match_all($pattern, $htmls, $matches);  
  6. for ($i=0; $i<=count($matches[0]); $i++) { 
  7.   preg_match_all("/alt=".+?"/",$matches[0][$i],$altimg);  
  8.   preg_match_all("/title=".+?"/",$matches[0][$i],$titleimg);  
  9. $t_alt=count($altimg[0]); 
  10. if($t_alt==0){ 
  11. $htmls=str_replace("<img","<img alt="{$title}"",$htmls); 
  12. $htmls=str_replace("<img","<img title="{$title}"",$htmls); 
  13. }    
  14. return $htmls; 
2.在模型里正文字段一般是newstext(也可以是其它字段),在字段处理函数文本框填上user_imgalt 
3.这样在帝国cms后台发布信息的时候就可以自动替换图片alt和title属性为信息标题了!

【审核人:站长】

99Ai聊天   收藏   加好友   海报   78分享
点赞(0)
打赏
标签:文章图片后台帝国CMS

发布者资料

热门文章

技术文摘

查看更多技术文摘
    首页
    栏目
    搜索
    会员
    投稿