php取文章第一张图片
<?php
function get_pic($str){
$pattern="/<[img|IMG].*?src=[\'|\"](.*?(?:[\.gif|\.jpg|\.png]))[\'|\"].*?[\/]?>/";
//$content = $str; //文章内容
preg_match_all($pattern,$str,$matchContent);
if(isset($matchContent[1][0])){
$temp=$matchContent[1][0];
}else{
$temp= $picpt;//在相应位置放置一张命名为no-image的jpg图片 //本实例为调用适应图片
}
$img_paths = $temp;
return $img_paths;
}
?>
PHP 正则替换
$content = preg_replace("/<a[^>]*href=[^>]*>|<\/[^a]*a[^>]*>/i","",$content); //替换链接
$content = preg_replace("/<img.*?>/si","",$content); //去图
PHP操作 TXT读写
$f='ditu.txt'; //文件名
$shu=file($f); //把文件的所有内容获取到数组里面
$n=count($shu); //获得总行数
$rnd=rand(0,$n); //产生随机行号
$rnd_line=$shu[$rnd]; //获得随机行
//$html = $rnd_line; //随机行内容
$zdh = $shu[0];
echo "自动推送{$a}-{$b}条数据,下次从第 {$c} 条开始 {$jt}<br />";
for($x=$a; $x<=$b; $x++)
{
$zdh = $shu[$x];
// echo $zdh."<br \>";
$uri .= $zdh.",";
//pinghtml($zdh);
}