用手机编程,功能太多经常出错,遂精简很多…希望虎哥提点修正建议,下面是
http://ai.me.ly/app/?read=substr源码(经UBB解析直接从缓存中拿出来的,小小修改一下就可用
http://ai.me.ly/file/?/pagecut.gz改.gz为.php)
<?php
error_reporting('0');
$START_TIME=microtime();
echo '<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN" "
http://www.wapforum.org/DTD/xhtml-mobile10.dtd">
<html xmlns="
http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="application/xhtml+xml" charset="UTF8"/>
<title>网页截取助手 Min.</title>
</head>
<body>
';
if(($url=preg_replace('#^(
http://)#i','',$_POST['url']))!=FALSE){
$url='http://'.$url;
$FileOpen=fopen($url,'rb');
while(!feof($FileOpen)){
$nr.=fgets($FileOpen,999999);
}
$nr=iconv($_POST['encode'],'UTF-8',$nr);
$nr=strip_tags(preg_replace('#(
|
|
|<br/ >|
|<hr>|<hr/>|<hr >|<hr />)#i',$_POST['br'],preg_replace('#</div>#i','</div>
',$nr)));
function 字串截取($内容,$开始,$结束){
$内容=substr($内容,strpos($内容,$开始));
$内容=substr($内容,0,strpos($内容,$结束));
return $内容.$结束;
}
$nr=字串截取($nr,$_POST['start'],$_POST['end']);
echo '执行结果:
<input type="text" name="result" value="'.htmlspecialchars($nr).'"/><hr/>';
}
echo '
<form accept-charset="utf-8" action="?" method="post">
<input type="hidden" name="read" value="substr"/>
目标网页URL:
<input type="text" name="url" value="http://"/>
网页编码:
<select name="encode"><option value="utf-8">UTF-8</option><option value="gb2312">GB2312</option></select>
截取[开始,可留空]:
<input type="text" name="start" value=""/>
截取[结束,可留空]:
<input type="text" name="end" value=""/>
换行匹配为:
<input type="text" name="br" value="'.chr("91").'br'.chr("93").'"/>
<input type="submit" value="Ok!"/>
</form><hr/>';
$END_TIME=microtime();
$runtime=$END_TIME - $START_TIME;
printf("执行时间: %.6f Sec.",$runtime);
echo '</body></html>';
?>