-1
//this is the code that creates the array and the output follows
while ($results_row = mysql_fetch_assoc($results)) {
        $returned_results[]= array(
                                    'partName'=>$results_row['partName'],
                                    'description'=>$results_row['description'],
                                    'price'=>$results_row['price']

//what is contained in the array is as follows
Array
(
[partName] => Cooler Master CM Storm Trooper Case
[description] => Armored appearance. Nicely placed handle at the top. At the front; ext
[price] => 36000
)
1

Array
(
[partName] => Cooler Master eXtreme Power Plus 500-Watt
[description] => Power Plus 500-Watt Power Supply,many SATA and peripheral connectors. 
[price] => 23000
)
1

Array
(
[partName] => Coolmax M-500B ATX Power Supply
[description] => The Coolmax M-500B ATX Power Supply has 5 SATA and 5 Peripheral, 8 pin
[price] => 20000
)

配列変数 ($returned_results[]) に含まれるデータを xml ファイルに書き込む必要があります。その後、xml テーブルに表示します。しかし、私は後者を管理できると思います。コード例を教えてください。よろしくお願いします!!

xml ファイルには、次のような配列データが含まれている必要があります。

<?xml version="1.0" encoding="utf-8"?>
     <results>
           <partName>Cooler Master CM Storm Trooper Case</partName>
           <description>Armored appearance. Nicely placed handle at the top. At the front; ext... </description>
           <price>36000</price>
     </results>
     <results>
            <partName>Cooler Master eXtreme Power Plus 500-Watt</partName>
            <description>Power Plus 500-Watt Power Supply,many SATA and peripheral connectors. ... </description>
             <price>23000</price>
    </results
    <results>
            <partName>Coolmax M-500B ATX Power Supply </partName>
            <description>The Coolmax M-500B ATX Power Supply has 5 SATA and 5 Peripheral, 8 pin..</description>
             <price>20000</price>
    </results>
4

2 に答える 2

0

echo(やなどではなくfwrite)PHP自体を使用してXMLを記述できます。

ob_start();
?>
<?xml version="1.0" encoding="utf-8"?>
<?php
while ($results_row = mysql_fetch_assoc($results)) {
?>
<results>
    <partName><?php echo htmlspecialchars($results_row['partName']);?></partName>
</results>
<?php
}

file_put_contents('file.xml', ob_get_clean());
于 2012-04-30T02:32:07.090 に答える
0

fwrite() を使用します。元:

$filecontents = file_get_contents ("file.xml");
$file = fopen(file.xml, w+);
//If you uncomment the next line, it will keep the current contents, if not it will overwrite it
//fwrite($file, $filecontents);
fwrite($file, $string/array-to-write);
fclose($file);
于 2012-04-30T01:53:03.787 に答える