Home  >  Article  >  php教程  >  获取新浪微博的微博秀内容存入数据表中

获取新浪微博的微博秀内容存入数据表中

PHP中文网
PHP中文网Original
2016-05-25 17:04:421268browse


function BlogRequest($line){
	$line=str_replace("&",'&',$line);
	if(empty($line)){
		return false;
	}else{
		$subject = file_get_contents(trim($line));
		$regex = "/(([^<>]+))/ism";
		preg_match_all($regex,$subject,$blogArray);
		$i=3;
		$sqlValue=array();
		foreach($blogArray[0] as $k=>$v){
			$sqlValue[]=explode(&#39;&#39;,$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=",&#39;&#39;,preg_replace("/<img[^\\]?([^\\&#39;\"\\s]*)[&#39;\"]?/is",&#39;&#39;,$value)));
				}

				$minAgo=1;
				if($key==2){//在日期中分离一个链接地址出来
					$timeStr=explode(&#39;span&#39;,$value);
					$changeStr=str_replace(&#39;class="weiboShow_mainFeed_listContent_actionTime"&#39;,&#39;&#39;,$timeStr[1]);//发布时间
					if(substr_count($changeStr,&#39;分钟前&#39;)>0){
						$oldmin=str_replace(&#39;分钟前&#39;,&#39;&#39;,trim(str_replace(&#39;>&#39;,&#39;&#39;,str_replace(&#39;"&#39;,&#39;&#39;,strip_tags($changeStr)))));
						$nowmin=date(&#39;i&#39;,time());
						$nowHore=date(&#39;H&#39;,time());
						if($oldmin>$nowmin){
							$fmin=$nowmin+60-$oldmin;
							$nowHore=$nowHore-1;
							$changeStr=date(&#39;Y-m-d &#39;,time()).$nowHore.":".$fmin;
						}else{
							$fmin=$nowmin-$oldmin;
							$changeStr=date(&#39;Y-m-d &#39;,time()).$nowHore.":".$fmin;
						}
						$minAgo=2;
					}else{
						if(substr_count($changeStr,&#39;今天&#39;)>0){
							$changeStr=date(&#39;Y-m-d&#39;,time()).str_replace("今天",&#39;&#39;,$changeStr);
						}else{
							$changeStr=date(&#39;Y-&#39;,time()).str_replace("日",&#39; &#39;,str_replace(" ",&#39;&#39;,str_replace("月",&#39;-&#39;,$changeStr)));
						};
					}
					//该博客链接 正则
					preg_match(&#39;/(?&#39;,&#39;&#39;,str_replace(&#39;"&#39;,&#39;&#39;,strip_tags($changeStr))));
					if($key==2){
						$sqlValue[$k][$key]=date(&#39;Y-m-d H:i&#39;,strtotime($sqlValue[$k][$key]));
					}
				}
			}
		}
		return $sqlValue;
	}
}

                   

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn