I want to write a script in PHP to process text files. I know some of the ways to accomplish this; I want to do this by leaving the only way. I want to be able to pass a file name, such as a traditional command line app.
For example:
php script.php textfile.txt or script.php textfile.txt
I think this can be done, because you argue for the musician. I do not have to do this in docs or Google
Can anyone tell me in the right direction? Or direct me to a language that supports it (perhaps Python or Groovy, if PHP is not an option)
In PHP, if you run it from the command line, then you can use any value Can treat. Inside your script.php , you will have to enter the $ argv array in these codes.
Your PHP script will be for the following:
& lt ;? Php // script.php print_r ($ argv); Then if you execute that file from the command line:
& gt; Php script.php foo bar testfile.txt
You will get the following result
Array ([0] => script.php [1] = & Gt; foo [2] = & gt; times [3] => testfile.txt) For more information, see.
It's very easy to create a script, but if you want to create an advanced command line tool program, then I recommend using it.
The console component lets you access each command The functionality will be explained within its class. Then you can create a simple "console" file which might be able to execute any of these commands. Take a look at a simple example app.
No comments:
Post a Comment