![]() |
|
首页 │ Apache │ Linux│ Java│ MySQL│ 注册│帮助 | |||
[php]function pic_insert($article){
$sysurlinfo = "http://";
if (preg_match_all("'src[\s\r\n]?=[\s\r\n]?[\\\]?[\'|\"]?(.*?\.(jpg|gif|png))[\\\]?[\'\"]?'si", $article, $matches, PREG_SET_ORDER)) {
//echo $matches[0][1];第一张图 可以把他做为新闻的首页图片
foreach ($matches as $key=> $value) {
$getimageurl =trim($value[1]);
$geturlinfo = strtolower($getimageurl);
$pos = strpos($geturlinfo, $sysurlinfo);
if($pos === false){
echo $geturlinfo;
$query_sort="select count(*) from pic where url='$geturlinfo'";
$res_sort=mysql_query($query_sort);
$count = mysql_fetch_row($res_sort);
if($count[0]==0){
$res_add=mysql_query("insert into pic set url='$geturlinfo',tm=NOW()");
}
}
}
}else{return false;}
return true;
}
pic_insert($article);[/php]
现在大家都是用到编辑器上传图片,但是图片上传后,就没有在对应文章中插入刚插入图片的地址
这样如果以后删除文章 但是图片没有删除 还有就是假如首页调用文章图片 还得另外上传
这段代码主要是利用正则读取文章中的图片地址 加入了区别项 是远程地址还是本地地址
呵呵 有是么改进希望大家 也交流交流

