Archive:PHP and MySQL Programming/Command Line Programming: Difference between revisions

wikademia>Webaware
m rvv, spelling
Line 1: Line 1:
== Introduction ==
== Introduction ==


PHP was traditionally used to help web administrators automate various mundane tasks and to add dynamism to the web pages. However, PHP (in its modern incarnation) is capable of much more. It is now being used in ways traditional programming languages are used. It is now possible to remove PHP applications from the constraints of the internet server. Now, PHP is being used to write GUI applications as well as command line applications. We shall now look at writing PHP applications for the command line.
PHP was traditionally used to help web administrators automate various mundane tasks and to add dynamism to the web pages. However, PHP (in its modern incarnation) is capable of much more. It is now being used in ways traditional programming languages are used. It is now possible to remove PHP applications from the constraints of the Internet server. Now, PHP is being used to write GUI applications as well as command line applications. We shall now look at writing PHP applications for the command line.


==Getting the PHP-CLI==
==Getting the PHP-CLI==
Line 16: Line 16:


  #!/bin/php
  #!/bin/php
venu
 
Note: You do not include this line in Windows!
Note: You do not include this line in Windows!


This should be the first line of the file, as it tells linux which interpreter to use for the file.
This should be the first line of the file, as it tells Linux which interpreter to use for the file.


The next thing you should do, is to make the file executable. This is done by the following Unix command :
The next thing you should do, is to make the file executable. This is done by the following Unix command :
Line 51: Line 51:
==Output Formatting==
==Output Formatting==


The main consideration to make when formating output in command line programming as apposed to generating HTML output is that a new line is not created by a <BR> tag, infact, any HTML tags you put into the output, will simply be displayed as plain text.
The main consideration to make when formatting output in command line programming as opposed to generating HTML output is that a new line is not created by a <BR> tag, in fact, any HTML tags you put into the output, will simply be displayed as plain text.


In order to create a new line in the command line, we need to use a control character, \n . Another usefull funtion when doing command line programming is this :
In order to create a new line in the command line, we need to use a control character, \n . Another useful function when doing command line programming is this :


  <?
  <?