<?php
// 获取文章内容
function body($id) {
$sql = "SELECT body FROM dede_archives WHERE id = '$id'";
$result = mysql_query($sql);
$row = mysql_fetch_assoc($result);
return $row['body'];
}
// 提取变量中第一个图片地址
function bodyimg($obj) {
if (isset($obj)) {
if (preg_match('/<img[^>]+src="([^">]+)"/i', $obj, $regs)) {
return $regs[1];
} else {
echo "Error: 没有图片地址!";
return 1;
}
}
}
// 修改数据表,插入获取的图像地址
function changearchives($pic, $id) {
$sql = "UPDATE dede_archives SET litpic = '$pic' WHERE id = '$id'";
$result = mysql_query($sql);
if ($result) {
echo "修改数据成功!";
} else {
echo "修改数据失败!";
}
}
// 显示数据表内容
$exec = "SELECT * FROM dede_archives WHERE typeid IN(494,495,496,497,498,499,500,501,502,503,504,374,375,376,377,378,379,488) AND litpic = ''";
$result = mysql_query($exec);
while ($rs = mysql_fetch_object($result)) {
$id = $rs->id;
echo $id . " ";
$body = body($id); // 获取文章内容
$pic = bodyimg($body); // 获取文章中的第一张图片地址
if ($pic) {
changearchives($pic, $id); // 插入获取的图片地址
}
}
mysql_close($conn);
?>
标签:body,缩略图,pic,第一张,Dedecms,result,mysql,echo,id From: https://www.cnblogs.com/hwrex/p/18512995