
文章插圖
PHP獲取指定網(wǎng)頁(yè)的HTML代碼并執(zhí)行輸出 , 這個(gè)方法主要是將所要或取目標(biāo)的URL地址的網(wǎng)站中獲取相關(guān)內(nèi)容到自己的網(wǎng)頁(yè)中 。代碼如下:
<?php $srcurl = "所要截取目標(biāo)的URL地址"; $handle = fopen($srcurl,"rb"); $content = fread($handle,10240000); $start_position=strpos($content,'截取內(nèi)容開始代碼A'); $start_position=$start_position+strlen('截取內(nèi)容開始代碼A'); $end_position=strpos($content,' 截取內(nèi)容結(jié)束代碼C'); $length=$end_position-$start_position; $content=substr($content,$start_position,$length); echo 'document.write("'.$content.'")'; ?>這樣就可以截取所需的內(nèi)容B 。追后賦予$content , 我在最后加上了echo ‘document.write為的是這樣就生成了JS代碼 。直接就成了JS代碼可直接在我想需要此內(nèi)容的地方用JS調(diào)用顯示 。這個(gè)你用php是不能獲得的 , 它又不是通過get或post提交的 可以給你的<td>一個(gè)id , 然后通過document.getElementByIdx_x_x_x(“name”).innerHtml就可以獲得了
代碼庫(kù)
導(dǎo)入指定網(wǎng)站或頁(yè)面代碼如下:
HP 獲取指定網(wǎng)站、網(wǎng)頁(yè)、URL 的 <head> 標(biāo)題:獲取網(wǎng)頁(yè)的標(biāo)題:
<? $url = 'http://www.*****.com/'; $lines_array = file($url); $lines_string = implode('', $lines_array); eregi("<head>(.*)</head>", $lines_string, $head); echo $head[0]; ?>HP 獲取網(wǎng)頁(yè)的 Html 源代碼輸出并執(zhí)行:<?php$lines = file('http://www.******.com/');foreach ($lines as $line_num => $line) {echo $line;}?>獲取網(wǎng)頁(yè)Html源代碼輸出并執(zhí)行2:<?phpecho file_get_contents("http://www.******.com/");?>PHP 獲取指定網(wǎng)站、網(wǎng)頁(yè)、URL 的 Html 源代碼:獲取網(wǎng)頁(yè)Html源代碼:
<?php$lines = file('http://www.*******.com/');foreach ($lines as $line_num => $line) {echo "Line <b>{$line_num}</b> : " . htmlspecialchars($line) . "<br />n";}?>特定網(wǎng)頁(yè)的特定代碼段
<?php $url = "http://******.****.com/a/20110428/005344.htm"; $contents = file_get_contents($url); //如果出現(xiàn)中文亂碼使用下面代碼 //$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 查找、判斷字符串在另一個(gè)字符串中是否存在:
<?phpif(stristr("www.****.com", "****.com")) { echo "查詢關(guān)鍵詞"; }?>
以上關(guān)于本文的內(nèi)容,僅作參考!溫馨提示:如遇健康、疾病相關(guān)的問題,請(qǐng)您及時(shí)就醫(yī)或請(qǐng)專業(yè)人士給予相關(guān)指導(dǎo)!
「愛刨根生活網(wǎng)」www.malaban59.cn小編還為您精選了以下內(nèi)容,希望對(duì)您有所幫助:- 開端小說兇手是誰(shuí)結(jié)局劇情解析簡(jiǎn)介 開端txt免費(fèi)閱讀迅雷下載
- php安裝教程詳解 php防sql注入函數(shù)
- 域名解析的6個(gè)步驟 用于域名解析什么意思
- html5零基礎(chǔ)入門教程 html技術(shù)的特點(diǎn)和功能
- html簡(jiǎn)單網(wǎng)頁(yè)代碼 html打開新窗口輸出文檔頁(yè)面
- 解析發(fā)旋球的技巧
- 解析乒乓球直板反手技巧
- 乒乓球的拉球技巧大解析
- 講解windows搭建php環(huán)境 php上傳文件到服務(wù)器要求
- 羽毛球殺球技巧解析
