请问 如何把字符串
中的orderNo和orderResult标签的数据全部提取出来。分别放到两个数组中?
$str = "<?xml version='1.0' encoding='gb2312'?><orderNo>10000000779460</orderNo><orderResult>5</orderResult><orderNo>10000000779461</orderNo><orderResult>11</orderResult>";htm;preg_match_all("/<([^>]+)>([^<]+)<\/\\1>/U", $str, $matches);$out = array();foreach ($matches[1] as $key => $value) { $out[$value][] = $matches[2][$key];}var_dump($out);
不是标准的xml输出吧?
$s = "
$a = simplexml_load_string($s);
print_r($a);
比如 我要把所有
把
我是从配送公司获取的这个字符串。目的就是要把
//xml 文件操作$simXml = simplexml_load_file('xmlpath');//取出orderNo$orderNo = array();foreach ($simXml->orderNo as $order) { $orderNo[] = (string)$order; //直接转换成字符串存放}//取出orderResult$orderResult = array();foreach ($simXml->orderResult as $res) { $orderResult[] = (string)$res;//直接转换成字符串存放,也可以转换成其他的;}
$s =<<< TXT<?xml version='1.0' encoding='gb2312'?> <orderNo>10000000779460</orderNo><orderResult>5</orderResult> <orderNo>10000000779461</orderNo><orderResult>11</orderResult>TXT;$d = array('orderNo' => 'array_order', 'orderResult' => 'arraresult');preg_match_all('#<(orderNo|orderResult)>(.+)</\1>#U', $s, $r);foreach($r[1] as $i=>$k) ${$d[$k]}[] = $r[2][$i];print_r($array_order);print_r($arraresult);
Array( [0] => 10000000779460 [1] => 10000000779461)Array( [0] => 5 [1] => 11)