澳门新葡萄京官网首页php preg_match获取新浪新闻代码

html head meta content=text/html;charset=gb2312/ title最新新闻/title
style body { background:#000000; padding:10px; font-size:12px;
margin:10px; text-align:center; } #main { background:#8B9C0D;
width:900px; margin:0px auto; } .mleft,.mmid,.mright { float:left; }
.mleft,.mright { background:#ABCDEF; width:300px; float:left; } .mmid {
background:#FECDBA; width:300px; float:left; } #footer {
background:#EB5566; height:80px; margin:0px auto; width:900px; } a {
display:block; text-align:left; } a:hover { font-size:13px;
color:#FF0000; } a:visited { color:#000000; background:#FFC080; }
/style /head body div id=main div class=mleft?php$str =
file_get_contents();preg_match_all(#div
class=s3h6(.*)/h6/div#i,$str,$match);

php生成 google map代码

 

for($i=0; $icount($match[0]); $i++){ echo
tttt.preg_replace(#(div.*h6)(.*)(/h6/div)#i,/2,$match[0][$i]).n;}?

titleGoogle Sitemap生成器/titlestyle type=text/css!–.agreement {border:
1px solid #666666;}.green {color: #00CC00;font-weight: bold;}.red
{color: #FF0000; font-weight: bold; }#scroll {border: 1px solid
#0000FF;line-height: 25px;height: 25px;width: 280px;text-align:
left;}.red{background-color:#999999;text-align:
center;filter:Alpha(opacity=80);/*透明度*/}#act {background-image:
url([img][/img]);height: 27px;width: 282px;}–/stylescriptvar
MyMar;function monitoring(){if(document.readyState ==’complete’){
window.location=’?i=’+query_get();}}function query_get(){ var querystr
= window.location.href.split(=);if(!Number(querystr[1])){var
value=0;}else{var value=Number(querystr[1]);}return Number(value)+1;
}MyMar=setInterval(‘monitoring()’,3000);/scriptdiv style=text-align:
center; id=all_adiv align=center id=actdiv align=center id=scrolldiv
class=red style=width:1%;/div/div/div/divdiv align=center正在检索:span
id=link/span/divdiv id=logs class=agreement style=height:420px;
overflow:auto;?
/*=========================================================== =
版权协议: = GPL ()
=———————————————————— = 摘
要:URL收集函数 PHP5 = 版 本:1.0
=———————————————————— = 开源stal
项目组 = 更新作者:jd808 = 最后日期:2008-4-18
============================================================*/
$file=’sitemap.xml’; //GOOGLE 需要的文件
执行时则做首页的临时URL存储文件$temp_file=’temp.xml’;//内页URL临时存储文件$url=;
//要搜索的网站$timea=time();//开始时间 用户无需理它
只管上面3个参数即可if(!$_GET[‘i’]){file_put_contents($file,”);
file_put_contents($temp_file,”);
file_put_contents($file,con($url,$timea)); echo script
window.location=’?i=bak’;
/script;}else{consts($_GET[‘i’],$timea,$file,$url);}function
con($url,$timea) //控制{echo script
document.getElementById(‘link’).innerHTML=’正在收集 .$url.
的信息!’;/script; $str = file_get_contents($url);
$collection_url=collection_url($str,$url);
$collection_url=array_flip($collection_url); foreach($collection_url
as $key=$value) {if(count(explode($url,$key))==2){$strurl.=$key./n;} }
return $strurl;}function consts($i,$timea,$file,$urlys){ $str
=file_get_contents($file); //读取页面数据并生产字符串
$url=explode(/n,$str); $sum=count($url)-1; if($i==’bak’) { $i=0; }
/*进度条*/ $wid=round($i/$sum*100,2).%;$div=div class=’red’
style=’width:.$wid.;’$wid/div;echo
‘scriptdocument.getElementById(scroll).innerHTML=’.$div.’;/script’;ob_flush();//释放缓存flush();
//将不再缓存里的数据发送到浏览器去 /*进度条END */
for($j=$i;$j$sum;$j++) { if(!$url[$j]){continue;}
if(!detection_url($url[$j])) //检测URL是否合法{continue;}
$timeb=time();//跟踪时间if(($timeb-$timea)=25){memory($collection_url,$j);
//存储数据}/* URL显示跟踪*/echo script
document.getElementById(‘link’).innerHTML=’.$url[$j].’;
/script;ob_flush();//释放缓存flush();
//将不再缓存里的数据发送到浏览器去/*
URL显示跟踪END*/$urlstr=@file_get_contents($url[$j]);$collection_url[]=collection_url($urlstr,$urlys);$timec=time();//跟踪时间if(($timec-$timea)=25){memory($collection_url,$j);
//存储数据}if($j==$sum-1){memorys(); //存储数据 主要是生成正式的xml}
}}function collection_url($str,$url)
//收集URL并返回一个数组{preg_match_all(‘/a.*?href=(.+?)/is’,$str,$matches);
$urlexp=$matches[1]; for($j=0;$jcount($urlexp);$j++)
{$urlexp[$j]=ltrim(str_replace(/r/n,”,$urlexp[$j]));$urlexp[$j]=ltrim(str_replace(/n,”,$urlexp[$j]));$urlexp[$j]=ltrim(str_replace(/r,”,$urlexp[$j]));if($urlexp[$j]==’#’){continue;}if($urlexp[$j]==’/#’){continue;}
if(!strchr($urlexp[$j],”)) {//没有$urlall[]=$url.$urlexp[$j];echo
$url.$urlexp[$j].’br’;print
scriptdocument.getElementById(‘logs’).scrollTop =
document.getElementById(‘logs’).scrollHeight;/script;ob_flush();//释放缓存flush();
//将不再缓存里的数据发送到浏览器去
}else{if(count(explode($url,$urlexp[$j]))==2){$urlall[]=$urlexp[$j];echo

 代码如下

/div div class=mmid?php$str =
file_get_contents();preg_match_all(#span
style=’padding-left:6px'(.*)/span/td#i,$str,$match);for($i=0;$icount($match[0]);$i++){
echo tttt.preg_replace(#span
style=’padding-left:6px'(.*)/span/td#i,/1,$match[0][$i]).n;}?

$urlexp[$j].’br’;print scriptdocument.getElementById(‘logs’).scrollTop

document.getElementById(‘logs’).scrollHeight;/script;ob_flush();//释放缓存flush();
//将不再缓存里的数据发送到浏览器去}else{unset($urlexp[$j]);}} } return
$urlall; //返回本页面搜索所得到的数组}function
memory($collection_url,$i){global
$temp_file;if(is_array($collection_url)){for($h=0;$hcount($collection_url);$h++){for($l=0;$lcount($collection_url[$h]);$l++){$strts.=$collection_url[$h][$l]./n;}}$wstr=file_get_contents($temp_file);file_put_contents($temp_file,$wstr.$strts);if($i==0){$i=2;}$k=$i-1;echo
script window.location=’?i=.$k.’; /script;exit;}}function memorys()
//主要是生成正式的xml{global
$temp_file,$file;$file_arr=array_flip(file($file));$temp_file_arr=array_flip(file($temp_file));$xmla=’?xml
version=1.0 encoding=UTF-8?’./r/n.’urlset
xmlns=’;$xmlc=/r/n/urlset;foreach($file_arr as
$keya=$valuea){$keya=ltrim(str_replace(/r/n,”,$keya));$keya=ltrim(str_replace(/n,”,$keya));$keya=ltrim(str_replace(/r,”,$keya));$xml.=’urlloc’.$keya.’/loclastmod’.date(Y-m-d,time()).’/lastmodchangefreqdaily/changefreq/url’;}foreach($temp_file_arr
as
$keyb=$valueb){$keyb=ltrim(str_replace(/r/n,”,$keyb));$keyb=ltrim(str_replace(/n,”,$keyb));$keyb=ltrim(str_replace(/r,”,$keyb));$xml.=’urlloc’.$keyb.’/loclastmod’.date(Y-m-d,time()).’/lastmodchangefreqdaily/changefreq/url’;}$strts=$xmla.$xml.$xmlc;file_put_contents($file,$strts);echo
scriptclearInterval(MyMar);
document.getElementById(‘link’).innerHTML=’URL已经收集完成!’;
document.getElementById(‘all_a’).innerHTML=’bXML生成已完成!/b’;
/script;}function detection_url($url){if(strrchr($url,’=’)){return
true;}if(substr($url,strlen($url)-1,1)==’/’){return true;}$postfix=
strrchr($url,’.’);switch ($postfix){case .php:return true;break;case
.html:return true;break;case .htm:return true;break;case .asp:return
true;break;case .aspx:return true;break;case .shtml:return
true;break;}return false;}?/div

<?php
/*PHP正则提取图片img标记中的任意属性*/
$str = ‘<center><img src=”/uploads/images/20100516000.jpg”
height=”120″ width=”120″><br
/>PHP正则提取或更改图片img标记中的任意属性</center>’;

/div div class=mright?php$str =
file_get_contents();preg_match_all(#td align=left
class=left(.*)/td#i,$str,$match);for($i=0;$icount($match[0]);$i++){
echo tttt.preg_replace(#td align=left
class=left(.*)/td#i,/1,$match[0][$i]).n;}?

//1、取整个图片代码
preg_match(‘/<s*imgs+[^>]*?srcs*=s*(‘|”)(.*?)1[^>]*?/?s*>/i’,$str,$match);
echo $match[0];

/div /div div id=footer/div /body/html

//2、取width
preg_match(‘/<img.+(width=”?d*”?).+>/i’,$str,$match);
echo $match[1];

//3、取height
preg_match(‘/<img.+(height=”?d*”?).+>/i’,$str,$match);
echo $match[1];

//4、取src
preg_match(‘/<img.+src=”?(.+.(jpg|gif|bmp|bnp|png))”?.+>/i’,$str,$match);
echo $match[1];

/*PHP正则替换图片img标记中的任意属性*/
//1、将src=”/uploads/images/20100516000.jpg”替换为src=”/uploads/uc/images/20100516000.jpg”)
print
preg_replace(‘/(<img.+src=”?.+)(images/)(.+.(jpg|gif|bmp|bnp|png)”?.+>)/i’,”${1}uc/images/${3}”,$str);
echo “<hr/>”;

//2、将src=”/uploads/images/20100516000.jpg”替换为src=”/uploads/uc/images/20100516000.jpg”,并省去宽和高
print
preg_replace(‘/(<img).+(src=”?.+)images/(.+.(jpg|gif|bmp|bnp|png)”?).+>/i’,”${1}
${2}uc/images/${3}>”,$str);

正则取图片img标记中的任意属性

 代码如下

$word = ‘<p height=”22″
align=”cenetr”>111 22</p> <img src=”/upload/images/aaa.jpg”
width=”100″><div style=”float:left;”>中国人</div>’;
//取整个图片代码
preg_match(‘/</s*img/s+[^>]*?src/s*=/s*(/’|/”)(.*?)//1[^>]*?//?/s*>/i’,$word,$matches);
echo $matches[0];//结果:<img src=”/upload/images/aaa.jpg”
width=”100″>

$word = ‘<p height=”22″ align=”cenetr”>111 22</p> <img
height=”60″ src=”/upload/images/aaa.jpg” width=100 style=><div
style=”float:left;”>中国人</div>’;
//取width
preg_match(‘/<img.+(width=/”?/d*/”?).+>/i’,$word,$matches);
echo $matches[1];

//取height
preg_match(‘/<img.+(height=/”?/d*/”?).+>/i’,$word,$matches);
echo $matches[1];

//取src
preg_match(‘/<img.+src=/”?(.+/.(jpg|gif|bmp|bnp|png))/”?.+>/i’,$word,$matches);
echo $matches[1];

/*正则替换去掉或改变图片img标记中的任意属性***************************************************************/
$str = ‘<p height=”22″ align=”cenetr”>111 22</p> <img
height=”60″ src=”/upload/images/aaa.jpg” width=100 style=><div
style=”float:left;”>中国人</div>
<p height=”22″ align=”cenetr”>31313 224344</p> <img
src=”/upload/images/bbb.jpg” height=”60″ width=100 style=><div
style=”float:left;”>1212121</div>’;

//改变src属性(此处将原来的src=”/upload/images/bbb.jpg”改变为src=”/upload/_thumbs/Images/bbb.jpg”)
print
preg_replace(‘/(<img.+src=/”?.+)(images//)(.+/.(jpg|gif|bmp|bnp|png)/”?.+>)/i’,”/${1}_thumbs/Images//${3}”,$str);

/*改变src属性,
此处将原来的src=”/upload/images/bbb.jpg”改变为src=”/upload/_thumbs/Images/bbb.jpg”,并舍弃宽和高
(比如你想在前台显示缩略图,但数据库中存储的是原图的路径。为什么要舍弃宽高??你缩略图啊!还是原图的宽高,会怎样???)
*/
print
preg_replace(‘/(<img).+(src=/”?.+)images//(.+/.(jpg|gif|bmp|bnp|png)/”?).+>/i’,”/${1}
/${2}_thumbs/Images//${3}>”,$str);
?>

发表评论

电子邮件地址不会被公开。 必填项已用*标注