Posts Tagged ‘PHP’

Executing PHP script from command line

This item was filled under [ PHP ]

Executing PHP scripts from command line is quite easy. You just need to know the right commands to execute your script. This procedure comes in handy while developing command line scripts.
*NIX OS:
/path/to/php -f /path/to/script.php
Windows OS:
X:\path\to\php.exe -f X:\path\to\script.php
-f parses and executes <file>. For a list of command line parameters, visit:
PHP: Using PHP from the command [...]

Continue reading...

PHP: Replace string in TXT file

This item was filled under [ PHP ]

Ever wanted to search, replace string in TXT files? Use PEAR’s File_SearchReplace and it will do the task for you. You can get a copy of package from: http://pear.php.net/package/File_SearchReplace/
Its quite easy to use. Here is sample code from PEAR’s website:
<?php
include 'File/SearchReplace.php' ;
$files = array( "test1.txt",
"test2.txt",
"test3.txt" ) ;
$ignoreline = array( "#", ":") ;
$snr = new File_SearchReplace( [...]

Continue reading...

Executing SHELL commands with PHP

This item was filled under [ PHP ]

My last post discusses executing batch file in .Net. And the process does use couple of crappy .Net lines! But the same can be done with PHP only in 1 line
<?php
$output = shell_exec('ls -lart');
echo "<pre>$output</pre>";
?>
For more details, read here.

Continue reading...