Re: grep leads me to an idea; php-ini.xml
| From: | Bertrand Mansion | Date: | Wed, 02 Apr 2003 12:13:21 +0000 |
| Subject: | Re: grep leads me to an idea; php-ini.xml | ||
| References: | 1 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-14787@lists.php.net to get a copy of this message | ||
<bmansion@mamasam.com> wrote :
> <urs@circle.ch> wrote :
>
>> hello
>>
>> just a few posts ago, i read this thing about using grep to
>> parse the php.ini path. i had this idea to put php.ini in an
>> xml file for some days and found a solution with wddx. having
>> no a way to grab the real php.ini path makes it even more
>> automatic. so here is my unconvetional way of moving php.ini
>> into xml:
>>
>> <?php
>> if(stristr(exec("which grep"), "Command not found") != 1)
>> {
>> $ini_html = exec("php -i | grep php.ini" );
>> $ini_arr = explode("</td>", $ini_html );
>> $ini_path = strip_tags(trim($ini_arr[1]) );
>>
>> $ini_vals = parse_ini_file($ini_path );
>> $packet_id = wddx_packet_start($ini_path );
>> wddx_add_vars($packet_id, "ini_vals");
>> echo $xml = wddx_packet_end($packet_id);
>> } else {
>> echo "There is no grep or no which either.\n";
>> }
>> ?>
>>
>> C:\php>php -f ini2xml.php > php-ini.xml
>>
>> what you do with it is up to you ;-)
>>
>> -urs
>
> Hi Urs,
>
> Converting ini to xml using the Config 1.4 package:
>
> $config = new Config();
> $root =& $config->parseConfig($ini_path, 'inifile');
> echo $root->toString('xml', array('name' => 'phpini'));
>
> Easy :)
Actually, not that easy. Looks like it works better with
$root =& $config->parseConfig($ini_path, 'inicommented');
As parse_ini_file() seems to convert Off to false (boolean) and On to 1
(int). With WDDX as in your example, Off is converted to an empty string and
On to a string '1'...
Bertrand Mansion
Mamasam