PHP獲取指定網頁的HTML代碼并執行輸出,這個方法主要是將所要或取目標的URL地址的網站中獲取相關內容到自己的網頁中。
代碼如下:
<?php $srcurl = "所要截取目標的URL地址"; $handle = fopen($srcurl,"rb"); $content = fread($handle,10240000); $start_position=strpos($content,'截取內容開始代碼A'); $start_position=$start_position+strlen('截取內容開始代碼A'); $end_position=strpos($content,' 截取內容結束代碼C'); $length=$end_position-$start_position; $content=substr($content,$start_position,$length); echo 'document.write("'.$content.'")'; ?>
這樣就可以截取所需的內容B。追后賦予$content,我在最后加上了echo ‘document.write為的是這樣就生成了JS代碼。 直接就成了JS代碼可直接在我想需要此內容的地方用JS調用顯示。這個你用php是不能獲得的,它又不是通過get或post提交的 可以給你的<td>一個id,然后通過
document.getElementByIdx_x_x_x(“name”).innerHtml就可以獲得了
代碼庫
導入指定網站或頁面代碼如下:
HP 獲取指定網站、網頁、URL 的 <head> 標題:
獲取網頁的標題:
<? $url = 'http://www.*****.com/'; $lines_array = file($url); $lines_string = implode('', $lines_array); eregi("<head>(.*)</head>", $lines_string, $head); echo $head[0]; ?>
HP 獲取網頁的 Html 源代碼輸出并執行:
<?php $lines = file('http://www.******.com/'); foreach ($lines as $line_num => $line) { echo $line; } ?> 獲取網頁Html源代碼輸出并執行2: <?php echo file_get_contents("http://www.******.com/"); ?>
PHP 獲取指定網站、網頁、URL 的 Html 源代碼:
獲取網頁Html源代碼:
<?php $lines = file('http://www.*******.com/'); foreach ($lines as $line_num => $line) { echo "Line <b>{$line_num}</b> : " . htmlspecialchars($line) . "<br />n"; } ?>
特定網頁的特定代碼段
<?php $url = "http://******.****.com/a/20110428/005344.htm"; $contents = file_get_contents($url); //如果出現中文亂碼使用下面代碼 //$getcontent = iconv("gb2312", "utf-8",$contents); //echo $contents; $from="<div id="Cnt-Main-Article-QQ"><P style="TEXT-INDENT: 2em">"; $end="</div>"; $q=cut($contents, $from, $end); echo $q; function cut($file,$from,$end){ $message=explode($from,$file); $message=explode($end,$message[1]); return $message[0]; } ?>
PHP 查找、判斷字符串在另一個字符串中是否存在:
<?php if(stristr("www.****.com", "****.com")) { echo "查詢關鍵詞"; } ?>
版權聲明:本文內容由互聯網用戶自發貢獻,該文觀點僅代表作者本人。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。如發現本站有涉嫌抄襲侵權/違法違規的內容, 請發送郵件至 舉報,一經查實,本站將立刻刪除。
發表評論
請登錄后評論...
登錄后才能評論