[Phpwm] [phpwm] Generate XML file from an array

Jon Spriggs jon.spriggs at gmail.com
Wed Mar 17 15:06:23 UTC 2010


I guess it depends on exactly what you want, but I'd probably do
something like this:

function make_array($array_object=array()) {
  $return='';
  if(is_array($array_object)) {
    foreach($array_object as $array_index=>$array_item) {
      $return.="<{$array_index}>\r\n";
        if(is_array($array_item)) {$return.=make_array($array_item);}
      $return.="</{$array_index}>\r\n";
    }
  } else {
    $return=$array_object;
  }
  return($return);
}

$file=fopen($file_name, "w");
fwrite($file, make_array($array));
fclose($file);
-- 
Jon "The Nice Guy" Spriggs LPIC-1 Certified




On Wed, Mar 17, 2010 at 2:55 PM, Gavin Kimpson <gkimpson at gmail.com> wrote:
> Hi guys,
>
> I would like to be able create a PHP script that will generate an XML
> file 'on the fly' from an array & then save this XML file within a
> directory on my server, eg 'filename.xml'
>
> I know there are probably many ways of doing this - I just wanted to
> know the best approach or indeed libraries/classes you guys may have
> come across that would do this with little fuss.
>
> Thanks in advance,
> Gav
>
> _______________________________________________
> Phpwm mailing list
> Website : http://www.phpwm.org
> Twitter : http://www.twitter.com/phpwm
> Facebook: http://www.facebook.com/group.php?gid=2361609907
>
> Post to list: Phpwm at mailman.lug.org.uk
> Archive etc : https://mailman.lug.org.uk/mailman/listinfo/phpwm
>



More information about the Phpwm mailing list