php 获取新浪微博的微博秀内容存入数据表中
获取新浪微博的微博秀内容存入数据表中 [代码片段(64行)]
function BlogRequest($line){
$line=str_replace("&",'&',$line);
if(empty($line)){
return false;
}else{
$subject = file_get_contents(trim($line));
$regex = "/(<div.*?>([^<>]+)<\\/div>)/ism";
preg_match_all($regex,$subject,$blogArray);
$i=3;
$sqlValue=array();
foreach($blogArray[0] as $k=>$v){
$sqlValue[]=explode('<!-- 图片 -->',$blogArray[0][$i]);
$i++;
}
foreach($sqlValue as $k=>$v){
foreach($v as $key=>$value){
$changeStr=$value;//内容不变真接存入数组
if($key==1){//图片只需地址
$changeStr=strip_tags(str_replace("alt=",'',preg_replace("/<img[^\\\\<\\\\>]?([^\\\\<\\\\>'\\"\\\\s]*)['\\"]?/is",'',$value)));
}
$minAgo=1;
if($key==2){//在日期中分离一个链接地址出来
$timeStr=explode('span',$value);
$changeStr=str_replace('class="weiboShow_mainFeed_listContent_actionTime"','',$timeStr[1]);//发布时间
if(substr_count($changeStr,'分钟前')>0){
$oldmin=str_replace('分钟前','',trim(str_replace('>','',str_replace('"','',strip_tags($changeStr)))));
$nowmin=date('i',time());
$nowHore=date('H',time());
if($oldmin>$nowmin){
$fmin=$nowmin+60-$oldmin;
$nowHore=$nowHore-1;
$changeStr=date('Y-m-d ',time()).$nowHore.":".$fmin;
}else{
$fmin=$nowmin-$oldmin;
$changeStr=date('Y-m-d ',time()).$nowHore.":".$fmin;
}
$minAgo=2;
}else{
if(substr_count($changeStr,'今天')>0){
$changeStr=date('Y-m-d',time()).str_replace("今天",'',$changeStr);
}else{
$changeStr=date('Y-',time()).str_replace("日",' ',str_replace(" ",'',str_replace("月",'-',$changeStr)));
};
}
//该博客链接 正则
preg_match('/(?<=href=")[\\w\\d\\.:\\/]*/',$timeStr[1],$aHref);
$sqlValue[$k][3]=str_replace('href=','',$aHref[0]);
$sqlValue[$k][4]=substr(strrchr($sqlValue[$k][3],"/"),1);
}
if($minAgo==2){
$sqlValue[$k][$key]=$changeStr;
}else{
$sqlValue[$k][$key]=trim(str_replace('>','',str_replace('"','',strip_tags($changeStr))));
if($key==2){
$sqlValue[$k][$key]=date('Y-m-d H:i',strtotime($sqlValue[$k][$key]));
}
}
}
}
return $sqlValue;
}
}
//该片段来自于http://outofmemory.cn
精彩图集
精彩文章






