How to extract the string & nbsp; & lt ;? Xml & nbsp; version = '1. 0' & nbsp; encoding = 'gb2312 '? & Gt; & nbsp; & lt; orderNo & gt; 10000000779460 & lt;/orderNo & gt; & lt; orderResult & gt; 5 & lt;/extract a string
How can I set the string
10000000779460 5 10000000779461 11
All data of the orderNo and orderResult labels in is extracted. Put them in two arrays respectively?
------ Solution --------------------
$str = "
10000000779460
5
10000000779461
11
";
htm;
preg_match_all("/<([^>]+)>([^<]+)<\/\\1>/U", $str, $matches);
$out = array();
foreach ($matches[1] as $key => $value) {
$out[$value][] = $matches[2][$key];
}
var_dump($out);
------ Solution --------------------
Isn't it a standard xml output?
$ S =" 10000000779460 5 10000000779461 11 ";
$ A = simplexml_load_string ($ s );
Print_r ($ );
------ Solution --------------------
// Xml file operations
$ SimXml = simplexml_load_file ('xmlpath ');
// Retrieve orderNo
$ OrderNo = array ();
Foreach ($ simXml-> orderNo as $ order)
{
$ OrderNo [] = (string) $ order; // directly convert to string for storage
}
// Retrieve orderResult
$ OrderResult = array ();
Foreach ($ simXml-> orderResult as $ res)
{
$ OrderResult [] = (string) $ res; // directly convert to string for storage, or convert to another;
}
I don't know if you want simple xml operations.
------ Solution --------------------
$ S = <TXT
10000000779460
5
10000000779461
11
TXT;
$ D = array ('orderno' => 'Array _ order', 'orderresult' => 'arraresult ');
Preg_match_all ('# <(orderNo
------ Solution --------------------
OrderResult)> (. +)
# 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
)