The Building Blocks of PHP
To start PHP coding, you need a text editor to code it. You can write PHP files, that are made up of plain text. You can produce them with any text editor, like Notepad on Windows, and BBEdit in Mac OS, or vi and Emacs on UNIX operating systems.
Type in the example in A PHP Script Incorporated into HTML and save the file, calling it something like first.php.
A Simple PHP Script
echo “Welcome to Tec News Web”
If you are not operating directly on the machine which will be serving your PHP script, you’ll in all probability use an FTP software for doing it, like WS-FTP for Windows or Fetch for Mac OS to upload you’re saved the document to the server. Once the document is in situ, you can be ready to access it via your browser. If there is no issue, then you can see the script’s output.
PHP Statements – Beginning and Ending a Block
When you write a PHP program, you must tell the PHP engine that you need to run those commands. If you do not try this, the code you write is mistaken for markup language and can be output to the browser. Your code can be named PHP with special tags that mark the beginning and end of PHP code blocks. The table shows four such PHP delimiter tags.
|Tag Style||Start Tag||End Tag|
|Script tags||<SCRIPT LANGUAGE=”PHP”>||</SCRIPT>|
As seen tags style in the above table, we can see only the standard and script tags are corrected way and that will work on any configuration. The short and ASP tags should be expressly enabled in your php.ini. php.ini’s short_open_tags switch must be enabled to enable detection for short tags, you need to ensure that the short_open_tags switch is about to on in php.ini.
short_open_tags = On;
Short tags are enameled by default, so you need to edit php.ini only if you want to disable them. To activate recognition for ASP-style tags. you must enable the asp_tags setting.
Asp_tags = On;
After you have got emended php.ini you must be able to use any of the four designs in your script. But you are going to use XML in your script you should disable the short tags() and work with the standard tags().
The echo statement and print () function
The echo statement is often used to output data and anything that echoes can be seen in the browser. You can also use the print function instead of the eco statement. Using echo or print () may be a matter of style once you examine different people’s scripts, you would possibly see either use.
Wheres echo is statement print is a function. A function can usually be called a command that performs a modified function in some way. Data sent to function almost always placed in parentheses after the function name. As an example, in this case, you’ll have sent the print () to operate a set of characters or a string. Strings should be fencelike in quotation marks either single or double.
The only line of code in a simple PHP script ended with a semicolon. The semicolon mark informs the PHP engine that you simply have completed a press release. Broadly, it is to PHP what a sentence is written or spoken English. Normally a sentence should end with a period and a statement should usually end with a semicolon. Expectations of this include statements that enclose other statements, and statements that end a block of code.
* Please do let us know your views on this article and what type of articles would you are interested to read.