首頁 >php教程 >php手册 >php读取html并截取字符串的简单代码

php读取html并截取字符串的简单代码

WBOY
WBOY原創
2016-06-13 12:19:571216瀏覽

复制代码 代码如下:


$title='脚本之家';
$hello='jb51.net!';
$file=file_get_contents('http://www.baidu.com');
$file=iconv("gbk//IGNORE","utf-8",$file);
//echo $file;
echo strpos($file,'

'); <br>echo substr($file,strpos($file,'<title>')+7,strpos($file,''-strpos($file,'')+7)); <br>$file=str_replace(array('百度一下','{hello}'),array($title,$hello), $file); <br>?> <br><br>下面是渝海用的小偷程序代码。大家可以多看下。脚本之家提供多款小偷程序。<br><p class="codetitle"><span style="CURSOR: pointer" onclick="doCopy('code4283')"><u>复制代码</u></span> 代码如下:</p> <p class="codebody" id="code4283"><br><?php <BR>function _url($Date){ <br>    $ch = curl_init(); <br>    $timeout = 5; <br>    curl_setopt ($ch, CURLOPT_URL, "$Date"); <br>    curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); <br>    curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)"); <br>    curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout); <br>    $contents = curl_exec($ch); <br>    curl_close($ch); <br>    return $contents; <br>} <br>$url="http://www.jb51.net"; <br>$contents.=_url($url); <br>echo $contents; //输出内容 <br>?><br></p>
陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn