Obtain data in xml using a regular expression
20110524
13.82
13.94
13.79
13.85
20110525
13.82
13.86
13.58
13.60
This is part of the xml file. it is to extract the values following the value tag one by one from it. it is better to know several records.
It can be applied to a defined function, such
Function value ($ a, $ B, $ c, $ d, $ n ){
.......
}
For (I = 1; I <(number of records); I ++ ){
Value ($ a, $ B, $ c, $ d, $ I );
}
Cycles:
First implementation of value (13.82, 13.94, 13.79, 13.85, 1)
Second implementation value (13.82, 13.86, 13.58, 13.60, 2)
Reply to discussion (solution)
A regular expression is not required. you can use the function to obtain xml data .. Thank you!
Php provides a dedicated method
$s =<<< XML
20110524
13.82
13.94
13.79
13.85
20110525
13.82
13.86
13.58
13.60
XML;$x = simplexml_load_string("
$s
");foreach($x->Record as $node) { $t = array(); foreach($node->Item as $v) $t[] = current($v->Value); print_r($t);}
Array( [0] => 20110524 [1] => 13.82 [2] => 13.94 [3] => 13.79 [4] => 13.85)Array( [0] => 20110525 [1] => 13.82 [2] => 13.86 [3] => 13.58 [4] => 13.60)
$count=preg_match_all('/
(.+?)<\/Record>/is',$str,$m);echo $count;preg_match_all('/
(.+?)<\/Value>/is',$str,$values);echo "
";print_r($values[1]);echo "
";/*2Array( [0] => 20110524 [1] => 13.82 [2] => 13.94 [3] => 13.79 [4] => 13.85 [5] => 20110525 [6] => 13.82 [7] => 13.86 [8] => 13.58 [9] => 13.60)*/
Thank you for the two great gods upstairs. The problem has been solved according to your methods ~~ Hey