php获取页面数据 php获取接口数据( 二 )


2、旧版本PHP3以前php获取页面数据的获取传值方法 。
3、修改PHP.ini文件php获取页面数据的配置 。
php获取指定网页内容一、用file_get_contents函数,以post方式获取url
?php
$url= '';
$data= https://www.04ip.com/post/array('foo'= 'bar');
$data= https://www.04ip.com/post/http_build_query($data);
$opts= array(
'http'= array(
'method'= 'POST',
'header'="Content-type: application/x-www-form-urlencoded\r\n".
"Content-Length: ". strlen($data) . "\r\n",
'content'= $data
)
);
$ctx= stream_context_create($opts);
$html= @file_get_contents($url,'',$ctx);
二、用file_get_contents以get方式获取内容
?php
$url='';
$html= file_get_contents($url);
echo$html;
?
三、用fopen打开url, 以get方式获取内容
?php
$fp= fopen($url,'r');
$header= stream_get_meta_data($fp);//获取报头信息
while(!feof($fp)) {
$result.= fgets($fp, 1024);
}
echo"url header: {$header} br":
echo"url body: $result";
fclose($fp);
?
四、用fopen打开url, 以post方式获取内容
?php
$data= https://www.04ip.com/post/array('foo2'= 'bar2','foo3'='bar3');
$data= https://www.04ip.com/post/http_build_query($data);
$opts= array(
'http'= array(
'method'= 'POST',
'header'="Content-type: application/x-www-form-
urlencoded\r\nCookie:cook1=c3;cook2=c4\r\n".
"Content-Length: ". strlen($data) . "\r\n",
'content'= $data
)
);
$context= stream_context_create($opts);
$html= fopen(';id2=i4','rb',false, $context);
$w=fread($html,1024);
echo$w;
?
五、使用curl库,使用curl库之前,可能需要查看一下php.ini是否已经打开了curl扩展
?php
$ch= curl_init();
$timeout= 5;
curl_setopt ($ch, CURLOPT_URL, '');
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$file_contents= curl_exec($ch);
curl_close($ch);
echo$file_contents;
?
php怎么获取当前页面 javascript的变量值可以使用ajax技术实现动态提交和返回php获取页面数据,不用刷新页面的所有内容 。基本代码如下php获取页面数据,可以酌情参考和修改php获取页面数据:
function showDate()
{
var xmlhttp;
var d = new Date();
if (window.XMLHttpRequest)
{
// IE7+, Firefox, Chrome, Opera, Safari 浏览器执行代码
xmlhttp=new XMLHttpRequest();
}
else
{
// IE6, IE5 浏览器执行代码
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4xmlhttp.status==200)
{
document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","getdate.php?q="+d,true);
xmlhttp.send();
}
【php获取页面数据 php获取接口数据】php获取页面数据的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于php获取接口数据、php获取页面数据的信息别忘了在本站进行查找喔 。

推荐阅读