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

Gavin Kimpson gkimpson at gmail.com
Wed Mar 17 15:24:54 UTC 2010


Thanks Jon! Done some minor tweaking to your original code and it is
more or less doing what I want now!

Thanks for the very quick response, that must be some kinda record lol :D

Cheers

On Wed, Mar 17, 2010 at 3:05 PM, Jon Spriggs <jon.spriggs at gmail.com> wrote:
> 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
>>
>
> _______________________________________________
> 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