$srv_ip = '127.0.0.1';//你的目标服务地址或频道.
$srv_port = 80;
$url = 'http://www.laor.cn/getcompanyinfo.aspx'; //接收你post的URL具体地址
$fp = '';
$resp_str = '';
$errno = 0;
$errstr = '';
$timeout = 10;
$post_str = "username=demo&str=aaaa";//要提交的内容.
//echo $url_str;
if ($srv_ip == '' || $dest_url == ''){
//echo('ip or dest url empty<br>');
}
//echo($srv_ip);
$fp = fsockopen($srv_ip,$srv_port,$errno,$errstr,$timeout);
if (!$fp){
echo('fp fail');
}
$content_length = strlen($post_str);
$post_header = "POST $url HTTP/1.1\r\n";
$post_header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$post_header .= "User-Agent: MSIE\r\n";
$post_header .= "Host: ".$srv_ip."\r\n";
$post_header .= "Content-Length: ".$content_length."\r\n";
$post_header .= "Connection: close\r\n\r\n";
$post_header .= $post_str."\r\n\r\n";
fwrite($fp,$post_header);
while(!feof($fp)){
$resp_str .= fgets($fp,512);//返回值放入$resp_str
}
fclose($fp);
echo($resp_str);//处理返回值.
//unset ($resp_str);输出为
HTTP/1.1 200 OK Connection: close Date: Tue, 15 Feb 2011 08:59:23 GMT Server: Microsoft-IIS/6.0 X-Powered-By: ASP.NET X-AspNet-Version: 2.0.50727 Cache-Control: private Content-Type: text/html; charset=gb2312 Content-Length: 599 ({'UserID':'0','UserName':'导入数据','CompanyName':'广州友好公寓e1','Province':'1','City':'2','District':'0'}) 但我只想要
({'UserID':'0','UserName':'导入数据','CompanyName':'广州友好公寓e1','Province':'1','City':'2','District':'0'})
这个 上面的怎么输出这些信息的呢?
$srv_port = 80;
$url = 'http://www.laor.cn/getcompanyinfo.aspx'; //接收你post的URL具体地址
$fp = '';
$resp_str = '';
$errno = 0;
$errstr = '';
$timeout = 10;
$post_str = "username=demo&str=aaaa";//要提交的内容.
//echo $url_str;
if ($srv_ip == '' || $dest_url == ''){
//echo('ip or dest url empty<br>');
}
//echo($srv_ip);
$fp = fsockopen($srv_ip,$srv_port,$errno,$errstr,$timeout);
if (!$fp){
echo('fp fail');
}
$content_length = strlen($post_str);
$post_header = "POST $url HTTP/1.1\r\n";
$post_header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$post_header .= "User-Agent: MSIE\r\n";
$post_header .= "Host: ".$srv_ip."\r\n";
$post_header .= "Content-Length: ".$content_length."\r\n";
$post_header .= "Connection: close\r\n\r\n";
$post_header .= $post_str."\r\n\r\n";
fwrite($fp,$post_header);
while(!feof($fp)){
$resp_str .= fgets($fp,512);//返回值放入$resp_str
}
fclose($fp);
echo($resp_str);//处理返回值.
//unset ($resp_str);输出为
HTTP/1.1 200 OK Connection: close Date: Tue, 15 Feb 2011 08:59:23 GMT Server: Microsoft-IIS/6.0 X-Powered-By: ASP.NET X-AspNet-Version: 2.0.50727 Cache-Control: private Content-Type: text/html; charset=gb2312 Content-Length: 599 ({'UserID':'0','UserName':'导入数据','CompanyName':'广州友好公寓e1','Province':'1','City':'2','District':'0'}) 但我只想要
({'UserID':'0','UserName':'导入数据','CompanyName':'广州友好公寓e1','Province':'1','City':'2','District':'0'})
这个 上面的怎么输出这些信息的呢?
$str = <<<eof
HTTP/1.1 200 OK Connection: close Date: Tue, 15 Feb 2011 08:59:23 GMT Server: Microsoft-IIS/6.0 X-Powered-By: ASP.NET X-AspNet-Version: 2.0.50727 Cache-Control: private Content-Type: text/html; charset=gb2312 Content-Length: 599 ({'UserID':'0','UserName':'导入数据','CompanyName':'广州友好公寓e1','Province':'1','City':'2','District':'0'})
eof;
preg_match('/(\(.*?\))/is',$str,$match);
print_r($match);
这个通过了 我怎么不行啊
就是说 我不想要这个信息啊
$str ="HTTP/1.1 200 OK Connection: close Date: Tue, 15 Feb 2011 08:59:23 GMT Server: Microsoft-IIS/6.0 X-Powered-By: ASP.NET X-AspNet-Version: 2.0.50727 Cache-Control: private Content-Type: text/html; charset=gb2312 Content-Length: 599 ({'UserID':'0','UserName':'导入数据','CompanyName':'广州友好公寓e1','Province':'1','City':'2','District':'0'})"
preg_match('/(\(.*?\))/is',$str,$match);
print_r($match);在帮忙各位 谢谢
HTTP/1.1 200 OK Connection: close Date: Tue, 15 Feb 2011 08:59:23 GMT Server: Microsoft-IIS/6.0 X-Powered-By: ASP.NET X-AspNet-Version: 2.0.50727 Cache-Control: private Content-Type: text/html; charset=gb2312 Content-Length: 599
Array ( [0] => ({'UserID':'0','UserName':'导入数据','CompanyName':'广州友好公寓e1','Province':'1','City':'2','District':'0'}) [1] => ({'UserID':'0','UserName':'导入数据','CompanyName':'广州友好公寓e1','Province':'1','City':'2','District':'0'}) )
就这样:
echo $match[1];
//preg_match('/(\(.*?\))/is',$str,$match);
preg_match('/(\{.*?\})/is',$str,$match);
print_r($match[0]);
$levels=json_decode($match[0]);
print_r($levels["CompanyName"]); 谢谢 PHP 怎么读取 JSON格式的呀 我这样写 不知道哪里错了。输出为空
$srv_ip = '127.0.0.1';//你的目标服务地址或频道.
$srv_port = 80;
$url = 'http://ypage.laoren.cn/getcompanyinfo.aspx'; //接收你post的URL具体地址
$fp = '';
$resp_str = '';
$errno = 0;
$errstr = '';
$timeout = 10;
$post_str = "userid=$lfjuid&str=aaaa";//要提交的内容.
//echo $url_str;
if ($srv_ip == '' || $dest_url == ''){
//echo('ip or dest url empty<br>');
}
//echo($srv_ip);
$fp = fsockopen($srv_ip,$srv_port,$errno,$errstr,$timeout);
if (!$fp){
echo('fp fail');
}
$content_length = strlen($post_str);
$post_header = "POST $url HTTP/1.1\r\n";
$post_header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$post_header .= "User-Agent: MSIE\r\n";
$post_header .= "Host: ".$srv_ip."\r\n";
$post_header .= "Content-Length: ".$content_length."\r\n";
$post_header .= "Connection: close\r\n\r\n";
$post_header .= $post_str."\r\n\r\n";
fwrite($fp,$post_header);
while(!feof($fp)){
$resp_str .= fgets($fp,512);//返回值放入$resp_str
}
fclose($fp);
//echo($resp_str);//处理返回值.
//unset ($resp_str);
//$str ="HTTP/1.1 200 OK Connection: close Date: Tue, 15 Feb 2011 08:59:23 GMT Server: Microsoft-IIS/6.0 X-Powered-By: ASP.NET X-AspNet-Version: 2.0.50727 Cache-Control: private Content-Type: text/html; charset=gb2312 Content-Length: 599 ({'UserID':'4','UserName':'uname','CompanyName':'company','Province':'1','City':'2','District':'0'})";
//preg_match('/(\(.*?\))/is',$str,$match);
preg_match('/(\{.*?\})/is',$resp_str,$match);
//print_r($match[0]);
preg_match('/(\'[0-9]\')/is',$match[0],$UserID);
$uid=substr($UserID[0],1,$UserID[0].length-1);