php怎么获取实时数据 php获取post数据

PHP如何实时取数据库//页面语句
var userid = getElementById('#username');
var passwd = getElementById('#password');
$.ajax({
url:'后台处理地址',
dataType:'JSON',
type:'POST',
data:'username=' userid 'passwd=' passwd,
error: function(){
//post失败
}
success: function(data) {//post成功
if (data.s=='ok') {
//成功信息,处理语句
}else {
//失败信息,处理语句
}
}
});
//后台语句
if (count($volist)0) {//有数据
......//处理语句
$data = https://www.04ip.com/post/array('s'='ok','html'=$html,'page'='span class="page"'.$show.'/span');
echo json_encode($data);
}else {//无数据
$html = "tr class='tr'td class='tc' colspan='11'暂无数据php怎么获取实时数据,等待添加~php怎么获取实时数据!/td/tr";
$data = https://www.04ip.com/post/array('s'='no','html'=$html);
echo json_encode($data);
}
大概是这样吧
PHP怎么获取表单提交的数据?。?/h2>一、用file_get_contents以get方式获取内容 , 需要输入内容为:
1、?php
2、$url='';
3、$html=file_get_contents($url);
4、echo$html;
5、?
二、用file_get_contents函数,以post方式获取url,需要输入内容为
1、?php
2、$url='';
3、$data=https://www.04ip.com/post/array('foo'='bar');
4、$data=https://www.04ip.com/post/http_build_query($data);
5、$opts=array(
6、'http'=array(
7、 'method'='POST',
8、 'header'="Content-type:application/x-www-form-urlencoded\r\n".
9、"Content-Length:".strlen($data)."\r\n",
10、 'content'=$data
11、)
12、);
13、$ctx=stream_context_create($opts);
14、$html=@file_get_contents($url,'',$ctx);
15、?
三、用fopen打开url,以get方式获取内容,需要输入内容为
1、?php
2、$fp=fopen($url,'r');
3、$header=stream_get_meta_data($fp);//获取信息
4、while(!feof($fp)){
5、$result.=fgets($fp,1024);
6、}
7、echo"urlheader:{$header}br":
8、echo"urlbody:$result";
9、fclose($fp);
10、?
四、用fopen打开url,以post方式获取内容 , 需要输入内容为
1、?php
2、$data=https://www.04ip.com/post/array('foo2'='bar2','foo3'='bar3');
3、$data=https://www.04ip.com/post/http_build_query($data);
4、$opts=array(
5、'http'=array(
6、'method'='POST',
7、'header'="Content-type:application/x-www-form-urlencoded\r\nCookie:cook1=c3;cook2=c4\r\n".
8、"Content-Length:".strlen($data)."\r\n",
9、'content'=$data
10、)
11、);
12、$context=stream_context_create($opts);
13、$html=fopen(';id2=i4','rb',false,$context);
14、$w=fread($html,1024);
15、echo$w;
16、?
五、用fsockopen函数打开url,以get方式获取完整的数据,包括header和body,需要输入内容为
1、?php
2、functionget_url($url,$cookie=false)
3、{
4、$url=parse_url($url);
5、$query=$url[path]."?".$url[query];
6、echo"Query:".$query;
7、$fp=fsockopen($url[host],$url[port]?$url[port]:80,$errno,$errstr,30);
8、if(!$fp){
9、returnfalse;
10、}else{
11、$request="GET$queryHTTP/1.1\r\n";
12、$request.="Host:$url[host]\r\n";
13、$request.="Connection:Close\r\n";
14、if($cookie)$request.="Cookie:$cookie\n";
15、$request.="\r\n";
16、fwrite($fp,$request);
17、while(!@feof($fp)){
18、$result.=@fgets($fp,1024);
19、}
20、fclose($fp);
21、return$result;
22、}
23、}
24、//获取url的html部分,去掉header
25、functionGetUrlHTML($url,$cookie=false)
26、{
27、$rowdata=https://www.04ip.com/post/get_url($url,$cookie);
28、if($rowdata)
29、{
30、$body=stristr($rowdata,"\r\n\r\n");
31、$body=substr($body,4,strlen($body));
32、return$body;
33、}
34、 returnfalse;
35、}
36、?
参考资料:
php-file_get_contents
php中如何实现实时更新数据呢?jQuery?网页一般是单向主动短链接,实时更新实在有些不便,即使一方掉线,另一方也不能及时感知 。一般所谓的实时刷新 , 大多采用定时刷新(轮询) , 或长轮询的方式做,ajax用于更新数据确实是比较简单方便的 。
轮询你就settimeout,长轮询你就每次接收数据成功后,再来一次长轮询 。但你链接别人的数据,了解一下供应商的刷新机制、周期再做考虑 。
当然这些都是伪实时,真的实时用http协议是不合适的 , 你得用flash插件做 。而你用的是api供应商的东西,这条路就基本走不通了 。
怎么用phpquery抓取网页实时数据?使用CI框架phpquery和框架并无关系 , 我现在也是用CI的
先将pq引入进来
$content = file_get_content('');
phpQuery::newDocumentHTML($content);
$containers = pq("xxxx");就可以了 , 但你要抓取这个网站数据,他数据是js加载的,所以你只需要
$content = file_get_content(';dataSet.nd=1440145968553dataSet.rows=100dataSet.page=1dataSet.sidx=dataSet.sord=asc');这个地址返回是json数据,你直接json_decode()就OK
【php怎么获取实时数据 php获取post数据】关于php怎么获取实时数据和php获取post数据的介绍到此就结束了 , 不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息 , 记得收藏关注本站 。

    推荐阅读