Pobieranie z XML gdzie id = z bazy danych

0

witam, może ktoś pomóc skonstruować typowy kod?
daje przyklad w bazie mam id 1 oraz id 3 oraz chcialbym je pobrac z xml tam gdzie jest to id 1 oraz id 2

<test> <test id="1" dodatkowy="+55"> <test id="2" dodatkowy="-5"> <test id="3" dodatkowy="+1"> <test id="4" dodatkowy="+5"> </test>

próbowałem tak

$file = " sciezka do pliku";
$f = @fopen($file, "r");

   $contents = fread($f, filesize($file)); 
    $tags = explode("<", $contents); 

    foreach($tags as $tag)
        {
        if(substr($tag, 0, 5) == "test")
            { 
            if($temppos = stristr($tag, "id=\"")) { 
                $temp = explode(" ", $temppos); 
                $houseid = $temp[0]; 
                }

            echo "<tr><td><center>".$temppos[0]."</center>";
            }

        }

ale nie działa

0
$db = file_get_contents("/tutaj-plik.xml");

preg_match_all("/<test id=\"([0-9]+)\" dodatkowy=\"([0-9\+\-]+)\">/i", $db, $results);
$i = 0;
$result = array();
foreach($results[1] as $r) {
$result[$r] = $results[2][$i];
$i++;
}

print_r($result);
0
PiDev napisał(a):
$db = file_get_contents("/tutaj-plik.xml");

preg_match_all("/<test id=\"([0-9]+)\" dodatkowy=\"([0-9\+\-]+)\">/i", $db, $results);
$i = 0;
$result = array();
foreach($results[1] as $r) {
$result[$r] = $results[2][$i];
$i++;
}

print_r($result);

mam taki wynik
Array
(
)

1 użytkowników online, w tym zalogowanych: 0, gości: 1