批量提取TXT存文本内容的第一张图片设为标题图片
好久没分享了,直接上代码?
保存成PHP文件放到/e/extend/新建目录/文件名.php
<?php require('../../class/connect.php'); //引入数据库配置文件和公共函数文件 require('../../class/db_sql.php'); //引入数据库操作文件 $link=db_connect(); //连接MYSQL $empire=new mysqlquery(); //声明数据库操作类 $editor=1; //声明目录层次 //$goodid=intval($_GET['id']); $cl=intval($_GET['classid']); $sql=$empire->query("select * from phome_ecms_news where classid={$cl} order by id"); while($r=$empire->fetch($sql)){ $pagetexturl=ECMS_PATH."/d/txt/".$r[newstext].".php"; $text=ReadFiletext($pagetexturl); $text=substr($text,12);//去除exit $nr=stripslashes($text); //册除反 $pattern = "/.*src="([^^]*?)".*/i"; //正则 //$pattern ='/<img.+src="?(.+.(jpg|gif|bmp|bnp|png))"?.+>/i'; preg_match_all($pattern,$nr,$matches); if(count($matches[1])>=1){ $diyfpic=$matches[1][0]; }else{ $diyfpic=$r['titlepic']; } $empire->query("update phome_ecms_news set titlepic='$diyfpic' where id=$r[id] limit 1"); } db_close(); //关闭MYSQL链接 $empire=null; //注消操作类变量 ?>
-------------------------------------------------------------------------------------------------------------------------------
简单按栏目ID提取,有什么想法更多功能,自己实现!!