您的位置 首页 php

PHP获取指定网页的HTML代码并执行输出

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”).inner Html 就可以获得了

PHP获取指定网页的HTML代码并执行输出

代码库

导入指定网站或页面代码如下:

HP 获取指定网站、网页、URL 的 <head> 标题:

获取网页的标题:

<? 
$url = ' 
$lines_array = file($url); 
$lines_string = implode('', $lines_array); 
eregi("<head>(.*)</head>", $lines_string, $head); 
echo $head[0]; 
?>
 

HP 获取网页的 Html 源代码输出并执行:

<?php
$lines = file('
 foreach  ($lines as $line_num => $line) {
echo $line;
}
?>
获取网页Html源代码输出并执行2:
<?php
echo file_get_contents("");
?>
 

PHP 获取指定网站、网页、URL 的 Html 源代码:

获取网页Html源代码:

<?php
$lines = file('
foreach ($lines as $line_num => $line) {
echo "Line <b>{$line_num}</b> : " . htmlspecialchars($line) . "<br />n";
}
?>
 

特定网页的特定代码段

<?php 
$url = ""; 
$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 "查询关键词";
 }
?>
 

文章来源:智云一二三科技

文章标题:PHP获取指定网页的HTML代码并执行输出

文章地址:https://www.zhihuclub.com/77038.shtml

关于作者: 智云科技

热门文章

评论已关闭

3条评论

  1. Hi, i think that i saw you visited my weblog thus i
    came to “return the favor”.I’m attempting to find things
    to enhance my web site!I suppose its ok to use some of your ideas!!

  2. slotterbaru, slotgacor, slotresmi, slotpalinggacor, slotidn, slotreceh,
    slotantirungkat, slotuangasli, infoslotgacor, rtpslotgacor, akunslotgacor, slotgacorterbaru, agenslotgacor, trikslotgacor, slotgampangmaxwin, maxwinslotolympus,
    slotlogin, bandarslot, bandarjudislot, bandarslotgacor,
    bandarslotonline, slotgacormaxwin, judislot88,
    idnslot77, judibolaparlay, judibolaresmi, bandarbola,
    slotfreebettanpadeposit, linksbobet, sbobetalternatif, sbobetlink, situsjudibola, judibolaterpercaya, judibolaeuro,
    bursataruhanbola, judibolagila, sbobetmain, sbobet88login, agensbobet, sbobetparlay, sbobetmobile, sbobetlogin, sbobetonline,
    sbobetasia, sbobetbola, judibolaonline, judibola, idnpoker, idnpokerasia,

  3. Undeniably believe that which you stated.
    Your favorite reason seemed to be on the web the simplest thing to be aware of.
    I say to you, I certainly get annoyed while people think about worries that they plainly do not
    know about. You managed to hit the nail upon the top
    as well as defined out the whole thing without having side effect ,
    people can take a signal. Will likely be back to get more.
    Thanks

网站地图