2011-12-24 4 views
0

私のXML文書は、次のノードが含まれます。読む値

1のMacBookの空気と4台のiPod

を私の質問は、「変数」値(1と4を読み取る方法です)、phpでそれらをエコーし​​ます。

答えて

1

simplexml XMLパーサーと正規表現を使用する必要があります。

<?php 
$string = <<<XML 
<?xml version='1.0'?> 
<document> 
    <description>1 macbook air and 4 ipods</description> 
</document> 
XML; 
$xml = simplexml_load_string($string); 
$description = $xml->description; 
preg_match('|(\d+) macbook air and (\d+) ipods|', $description, $match); 

print_r($match[1] . ' '); 
print_r($match[2]);