[PHP] 纯文本查看 复制代码
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta content='width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0' name='viewport' />
<meta name="viewport" content="width=device-width" />
<title>标题</title>
</head>
<body>
<?php
set_time_limit(0);
function get_basename($filename){
return preg_replace('/^.+[\\\\\\/]/', '', $filename);
}
function https_request($url, $data = null){
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
if (!empty($data)){
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
}
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($curl);
curl_close($curl);
return $output;
}
function xzimg($pic,$houzhui){
$filetime = time(); //得到时间戳
$filepath = "img/";//图片保存的路径目录
if(!is_dir($filepath)){
mkdir($filepath,0777, true);
}
$xx=strtolower($pic);
if($houzhui==''){
if(strstr($xx,".jpg")){
$houzhui="jpg";
}
if(strstr($xx,".png")){
$houzhui="png";
}
if(strstr($xx,".gif")){
$houzhui="gif";
}
if(strstr($xx,".bmp")){
$houzhui="bmp";
}
if(strstr($xx,".jpeg")){
$houzhui="jpeg";
}
}
if(strstr($xx,"mmbiz.qpic.cn")){
$filename = date("YmdHis",$filetime).rand(100,999).'.'.$houzhui;
}else{
$dd=get_basename($pic);
$cc=parse_url($pic);
$dd=str_replace($cc["query"],"",$dd);
$dd=str_replace("?","",$dd);
$filename = $dd;
}
$newfname = $filepath.$filename;
$data = file_get_contents($pic);
$fp = fopen($newfname,"w");
fwrite($fp, $data);
fclose($fp);
if (file_exists($newfname)) {
echo $filename.'<br>';
}
}
function imgall($url){
$str = https_request($url);
$list = array(); //这里存放结果map
$c1 = preg_match_all('/<img\s.*?>/', $str, $m1); //先取出所有img标签文本
//print_r($m1);
for($i=0; $i<$c1; $i++) { //对所有的img标签进行取属性
$c2 = preg_match_all('/(\w+)\s*=\s*(?:(?:(["\'])(.*?)(?=\2))|([^\/\s]*))/', $m1[0][$i], $m2); //匹配出所有的属性
for($j=0; $j<$c2; $j++) { //将匹配完的结果进行结构重组
$list[$i][$m2[1][$j]] = !empty($m2[4][$j]) ? $m2[4][$j] : $m2[3][$j];
}
}
for($k=0;$k<count($list);$k++){
$src=$list[$k]["src"];
if(strstr($src,"mmbiz.qpic.cn")){
$size = getimagesize($src);
$fp = fopen($src, "rb");
if ($size && $fp) {
if(strstr($size['mime'],".png")){
$houzhui="png";
}elseif(strstr($size['mime'],".gif")){
$houzhui="gif";
}else{
$houzhui="jpg";
}
xzimg($src,$houzhui);
}
}else{
$houzhui=get_extension($src);
if($houzhui!=''){
xzimg($src,$houzhui);
}
}
}
}
function get_extension($file)
{
return pathinfo($file, PATHINFO_EXTENSION);
}
$lianjie=trim($_POST["wd"]);
?>
<form action="?" method="post">
<input value="" name="wd" style="width: 400px; height: 20px;">
<input type="submit" value="go" style="padding:4px 10px;font-size:16px;">
</form>
<?php
if($lianjie!=''){
imgall($lianjie);
echo $lianjie;
}
?>