摘取字符串
请问 如何把字符串
中的orderNo和orderResult标签的数据全部提取出来。分别放到两个数组中?
------解决方案--------------------
$str = "<?xml version='1.0' encoding='gb2312'?><orderNo>10000000779460</orderNo><orderResult>5</orderResult><orderNo>10000000779461</orderNo><orderResult>11</orderResult>";<br />htm;<br />preg_match_all("/<([^>]+)>([^<]+)<\/\\1>/U", $str, $matches);<br />$out = array();<br />foreach ($matches[1] as $key => $value) {<br /> $out[$value][] = $matches[2][$key];<br />}<br />var_dump($out);
<br />//xml 文件操作<br />$simXml = simplexml_load_file('xmlpath');<br />//取出orderNo<br />$orderNo = array();<br />foreach ($simXml->orderNo as $order) <br />{<br /> $orderNo[] = (string)$order; //直接转换成字符串存放<br />}<br />//取出orderResult<br />$orderResult = array();<br />foreach ($simXml->orderResult as $res) <br />{<br /> $orderResult[] = (string)$res;//直接转换成字符串存放,也可以转换成其他的;<br />}<br />
$s =<<< TXT<br /><?xml version='1.0' encoding='gb2312'?> <orderNo>10000000779460</orderNo><orderResult>5</orderResult> <orderNo>10000000779461</orderNo><orderResult>11</orderResult><br />TXT;<br /><br />$d = array('orderNo' => 'array_order', 'orderResult' => 'arraresult');<br />preg_match_all('#<(orderNo<br><font color='#FF8000'>------解决方案--------------------</font><br>orderResult)>(.+)</\1>#U', $s, $r);<br /><br />foreach($r[1] as $i=>$k) ${$d[$k]}[] = $r[2][$i];<br /><br />print_r($array_order);<br />print_r($arraresult);<br />
Array<br />(<br /> [0] => 10000000779460<br /> [1] => 10000000779461<br />)<br />Array<br />(<br /> [0] => 5<br /> [1] => 11<br />)<br /><br />