Rajasekar
Rajasekar

Reputation: 18948

How to convert records in a table to xml format in PHP?

I fetched some records from a table named a2h_member in php. i want to convert it into XML format. How can i do this?. Give me some suggestions or code. Please Help me

Upvotes: 0

Views: 669

Answers (1)

RageZ
RageZ

Reputation: 27313

The simpler the better:

$xml = '<?xml version="1.0" encoding="UTF-8" ?><result>';

foreach($result as $row){
 $xml .= '<row>';
 foreach($row as $key=>$value){
   $xml .= "<{$key}><![CDATA[{$value}]]></{$key}>";
 }
 $xml .= '</row>';
}
$xml .= '</result>';

Upvotes: 2

Related Questions