http://www.oschina.net/code/snippet_60100_25087
<?phpclass Express {private $expressname =array ();//encapsulates The Courier name function __construct () {$this-> ; expressname = $this->expressname (); }/* * method for capturing Web content */Private Function getcontent ($url) {if (Function_exists ("file_get_contents") { $file _contents = file_get_contents ($url); }else{$ch = Curl_init (); $timeout = 5; curl_setopt ($ch, Curlopt_url, $url); curl_setopt ($ch, Curlopt_returntransfer, 1); curl_setopt ($ch, Curlopt_connecttimeout, $timeout); $file _contents = curl_exec ($ch); Curl_close ($ch); } return $file _contents; }/* * Gets the corresponding name and the corresponding pass value method */Private Function Expressname () {$result = $this->getcontent ("http://www.k uaidi100.com/"); Preg_match_all ("/data\-code\=\" (? p<name>\w+) \ "\>\<span\> (? p<title>.*) \<\/span>/iu ", $result, $data); $name = Array (); ForeAch ($data [' title '] as $k = + $v) {$name [$v] = $data [' name '] [$k]; } return $name; }/* * method to parse the object array * @param $json input Object Arrays * Return $data array */Private function Json_arr Ay ($json) {if ($json) {foreach (array) $json as $k = = $v) {$data [$k] =!is_string ($v)? $th Is->json_array ($v): $v; } return $data; }/* * Returns an array of $data arrays * @param $name Express name * The name of The courier support entered is as follows * (Shen Tong-ems-Shun Fung-Yuantong-Zhong Tong-such as Wind Tatsu-Yun da-daily-Huitong-Pang-darbond-Home delivery-An Sinda-Parcel Mail-FedEx Logistics * DHL Express-Daejeon Logistics-de bang Logistics-ems domestic-ems International e-mail Bao-van Courier-China Express-registered-total speed-International parcel * Huitong Express-Huayu Logistics-hui Qiang Express-Jia Ji Express -Jia Yi Logistics-Canada Post-Express-Express-Longbang Express-FedEx-Union Hao Tong * can reach Courier-like the wind-Sweden post-all one Express-Pang Express-full-day pass-Shentong Express-Shun Fung Express-Express Courier-tnt Express-Daily Express * heaven and earth Huayu-ups Express-new state logistics-new Egg logistics-Hongkong Post -Yuantong Express-Yun da Express-Postal parcel-excellent speed express-in the express delivery-in-rush-home Delivery-Mail Logistics * @param $order Courier number * $data [' Ischeck '] ==1 has signed * $d ata[' data ' express real-time query status array */Public function GetOrder ($name, $order) { $keywords = $this->expressname[$name]; $result = $this->getcontent ("http://www.kuaidi100.com/query?type={$keywords}&postid={$order}"); $result = Json_decode ($result); $data = $this->json_array ($result); return $data; }} $a = new Express (); $result = $a->getorder ("All-in-one Express", "111309582915"); Var_dump ($result);? >
PHP Express Query