Re: Using PHP for search and replace
| From: | Paul Gregg | Date: | Mon, 06 Jan 2003 10:35:55 +0000 |
| Subject: | Re: Using PHP for search and replace | ||
| References: | 1 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-93173@lists.php.net to get a copy of this message | ||
In mail.php.internals, Jean-Michel Dault <jmdault@mandrakesoft.com> 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.