{"result":"1","realms":[{"activeMode":"0","chargeType":"0","closeDate":null,"createDate":{"date":6,"day":4,"hours":0,"minutes":0,"month":7,"nanos":0,"seconds":0,"time":1249488000000,"timezoneOffset":-480,"year":109},"emigrateLimit":"1","gameId":9,"id":9037,"isp":"2","issuerId":7,"name":"网通6-13区","state":"1","subdbId":24},{"activeMode":"0","chargeType":"0","closeDate":null,"createDate":{"date":10,"day":2,"hours":0,"minutes":0,"month":7,"nanos":0,"seconds":0,"time":1281369600000,"timezoneOffset":-480,"year":110},"emigrateLimit":"1","gameId":9,"id":7090026,"isp":"2","issuerId":7,"name":"网通53区[魔幻圣域]","state":"1","subdbId":26}]}  在这段字符串中提取 id isp name这三个对应的值,比如
"id":9037,"isp":"2","issuerId":7,"name":"网通6-13区",中提取出来的id为:9037,isp为:2, name为:网通6-13区
麻烦各位大侠....在线等......

解决方案 »

  1.   

    本帖最后由 xuzuning 于 2010-09-17 16:33:16 编辑
      

  2.   

    版主强。。
    $s = '{"result":"1","realms":[{"activeMode":"0","chargeType":"0","closeDate":null,"createDate":{"date":6,"day":4,"hours":0,"minutes":0,"month":7,"nanos":0,"seconds":0,"time":1249488000000,"timezoneOffset":-480,"year":109},"emigrateLimit":"1","gameId":9,"id":9037,"isp":"2","issuerId":7,"name":"网通6-13区","state":"1","subdbId":24},{"activeMode":"0","chargeType":"0","closeDate":null,"createDate":{"date":10,"day":2,"hours":0,"minutes":0,"month":7,"nanos":0,"seconds":0,"time":1281369600000,"timezoneOffset":-480,"year":110},"emigrateLimit":"1","gameId":9,"id":7090026,"isp":"2","issuerId":7,"name":"网通53区[魔幻圣域]","state":"1","subdbId":26}]}';$pat = '`,"id":(\d+),"isp":"(\d+)","issuerId":(\d+),"name":"([^"]+)"`';
    preg_match_all($pat, $s, $arr);
    print_r($arr); 
      

  3.   


    $pattern = '/"id":\d+,"isp":"\d+","name":"[^,.]+"/';preg_match_all($pattern, $string, $match);print_r($match[0]);//过滤掉你不要的内容
      

  4.   

    这个就是json格式,不必要再写正则的
      

  5.   

    php对于json的编码格式还是很复杂的,用正则解析json恐怕是得不偿失。
    建议楼主仔细研究一下json的格式说明。