HTTP/1.1 200 OK Server: Apache-Coyote/1.1 Date: Wed, 17 Oct 2012 07:05:19 GMT Content-Type: application/json Content-Length: 169 Connection: close {"UserDTO":{"comIndustry":2,"comType":2,"email":"[email protected]","industry":3,"telephone":13333333333,"userId":111944,"userType":1,"username":"请输入公司名称"}}
有上面这一串字符,{"UserDTO":{"comIndustry":2,"comType":2,"email":"[email protected]","industry":3,"telephone":13333333333,"userId":111944,"userType":1,"username":"请输入公司名称"}}这一段是我要正则提取出来的  谢谢!!

解决方案 »

  1.   

    preg_match('/\{(.*)\}/s',$s,$m);
    echo $m[1];
      

  2.   

    费那劲干什么?抓取时不要http头不就行了?
      

  3.   

    怎么不要头呢  ?代码如下$Cookie=$config_login["cookie_name"]."=".$cookie_value.";";
    try{
    $fp = fsockopen($config_login["host"], $config_login["prot"], $errno, $errmsg);
    fwrite($fp, "GET ".$config_login["sitepate"].$config_login["url"]." HTTP/1.1\r\n");
    fwrite($fp, "Accept: application/".$config_login["accept"]."\r\n");
    fwrite($fp, "Cookie: ".$Cookie.";\r\n");
    fwrite($fp, "Host: ".$config_login["host"]."\r\n");
    fwrite($fp, "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.2.16) Gecko/20110319 Firefox/3.6.16 GTB7.1\r\n");
    fwrite($fp, "Connection: Close\r\n\r\n");
    } catch (Exception $e) {
    die('fsock error');
    exit;
    } $xmlstr = '';
    while (!feof($fp)) {
    $xmlstr .= fgets($fp, 128);
    }
         fclose($fp);
      

  4.   

    $h = 0;
    while (!feof($fp)) {
      $t = fgets($fp, 128);
      if(!$h && $t == "Connection: close\r\n") {
         $xmlstr = '';
         $h++;
      }
      $xmlstr .= $t;
    }