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 "查詢關鍵詞";
}
?>
原創文章,作者:投稿專員,如若轉載,請註明出處:https://www.506064.com/zh-tw/n/252528.html
微信掃一掃
支付寶掃一掃