Re: [PHP-DEV] Using PHP for search and replace

2003-01-06 Thread Jean-Michel Dault
Le lun 06/01/2003 à 06:35, Paul Gregg a écrit :
> > perl -pi -e "s|^;extension=mysql.so|extension=mysql.so|" /etc/php.ini
> > Is there a quick and easy way to do this kind of thing in PHP? Or would
> I was about to say "Ask the RPM makers" until I saw who was asking :-)

Everyone's doing that.. RedHat, SuSe, PLD, Mandrake... so obviously no
RPM guy has ever tried something else ;-)

> How about:
> php -q -r '$lines=file("/etc/php.ini"); $f=fopen("/etc/php.ini", "w"); \
> foreach ($lines as $line) { fwrite($f, preg_replace("/^;extension=mysql.so/",\
> "extension=mysql.so", $line)); } fclose($f);'

I'll try that, thanks!

> I presume perl is no longer a "standard" package installed with either
> redhat or mandrake thus the question ?

No, it's just that it's pretty weird to have a Prereq: perl in a PHP
package. Imagine the irony, you install the best scripting language
(PHP) and you need its competitor (Perl) to be able to use install it
;-)

Jean-Michel


--
PHP Development Mailing List 
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP-DEV] Using PHP for search and replace

2003-01-06 Thread Paul Gregg
In mail.php.internals, Jean-Michel Dault <[EMAIL PROTECTED]> wrote:
> Hello all,
> 
> Currently, both Mandrake and RedHat use the following trick:
> perl -pi -e "s|^;extension=mysql.so|extension=mysql.so|" /etc/php.ini
> 
> This sucks, because you then need perl to install a PHP extension.
> We sure could use sed, but this requires a temporary file, and this
> creates some security risks.
> 
> Is there a quick and easy way to do this kind of thing in PHP? Or would
> this be something that we could integrate?

I was about to say "Ask the RPM makers" until I saw who was asking :-)

How about:

php -q -r '$lines=file("/etc/php.ini"); $f=fopen("/etc/php.ini", "w"); \
foreach ($lines as $line) { fwrite($f, preg_replace("/^;extension=mysql.so/",\
"extension=mysql.so", $line)); } fclose($f);'

or php-cli -r '..' (as above)

?

It'd probably be better to read from the php.ini-dist file or the source in
the package and write to php.ini, but the above will work* if it isn't 
interrupted (which would probably cause other issues with the rpm, so isn't
a biggie).
* I typed this out without testing it, so it might not work :)

I presume perl is no longer a "standard" package installed with either
redhat or mandrake thus the question ?

Paul.

-- 
PHP Development Mailing List 
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP-DEV] Using PHP for search and replace

2003-01-04 Thread Jean-Michel Dault
Hello all,

Currently, both Mandrake and RedHat use the following trick:
perl -pi -e "s|^;extension=mysql.so|extension=mysql.so|" /etc/php.ini

This sucks, because you then need perl to install a PHP extension.
We sure could use sed, but this requires a temporary file, and this
creates some security risks.

Is there a quick and easy way to do this kind of thing in PHP? Or would
this be something that we could integrate?

And I know there's a new solution with the new config-file-scan-dir, but
my question is a general search-and-replace solution.

Any thoughts?

Jean-Michel


-- 
PHP Development Mailing List 
To unsubscribe, visit: http://www.php.net/unsub.php