ajax 在php页面输出html代码,PHP获取网页的 Html源代码输出并执行

$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提交的

可以给你的

一个id,然后通过

document.getElementByIdx_x_x_x("name").innerHtml就可以获得了

PHP

获取指定网站、网页、URL 的

标题:

获取网页的标题:

 $url = 'http://www.baidu.com/'; $lines_array = file($url); $lines_string = implode('', $lines_array); eregi("

(.*)",

$lines_string, $head); echo $head[0]; ?>

PHP 获取网页的

Html 源代码输出并执行:

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

$lines = file('http://www.baidu.com/');

foreach ($lines as $line_num => $line) {

echo $line;

}

?>

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

echo file_get_contents("http://www.baidu.com/");

?>

PHP

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

获取网页Html源代码:

$lines = file('http://www.baidu.com/');

foreach ($lines as $line_num => $line) {

echo "Line

{$line_num}

: " . htmlspecialchars($line) . "

/>\n";

}

?>

特定网页的特定代码段

$url =

"http://finance.qq.com/a/20110428/005344.htm";

$contents = file_get_contents($url);

//如果出现中文乱码使用下面代码

//$getcontent = iconv("gb2312",

"utf-8",$contents);

//echo $contents;

$from="

id=\"Cnt-Main-Article-QQ\">

style=\"TEXT-INDENT: 2em\">";

$end="

";

$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

查找、判断字符串在另一个字符串中是否存在:

if(stristr("www.baidu.com", "baidu.com"))

{

echo

"百度";

}

?>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值