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 create them with any text editor, such as Notepad on Windows, Simple Text, and BBEdit in Mac OS, or vi and Emacs on UNIX operating systems. Most popular markup language editors offer a minimum of some support for PHP.

 

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 

<?php

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 ought to 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 place, you should be able to access it via your browser. If there is no issue, then you can see the script’s output.

 

 

Beginning and Ending a Block of PHP Statements

When writing PHP, you need to inform the PHP engine that you want it to execute your commands. If you do not try this, the code you write is mistaken for markup language and can be output to the browser. You can designate your code as 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
Standard tags <?php ?>
Short tags <? ?>
ASP tags <% %>
Script tags <SCRIPT LANGUAGE=”PHP”> </SCRIPT>

 

As seen tags style in 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 style tags must be explicitly enabled in your php.ini. To activate recognition for short tags, you must make sure that the short_open_tags switch is set 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 edited php.ini you should be able to use any of the four styles 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(<?php ?>).

 

 

The echo statement and print () function 

Simply the echo statement is used to output data. in most cases, anything output by echo ends up viewable in the browser. You could also have used the print function in place of the echo statement. Using echo or print () is a matter of taste when you look at other people’s scripts, you might see either use.

 

Wheres echo is statement print is a function. A function is a command that performs an action usually modified in some way by data provided for it.  Data sent to function almost always placed in parentheses after the function name. in this case, you could have sent the print () function a collection of characters or a string. Strings must always be enclosed in quotation marks either single or double. for example

 

<?

Print (“Welcome to Tec News Web”);

?>

 

The only line of code in a simple PHP script ended with a semicolon. The semicolon informs the PHP engine that you have completed a statement. A statement represents an instruction to the PHP engine. Broadly, it is to PHP what a sentence is written or spoken English. A sentence should usually end with a period. A statement should usually end with a semicolon. Expectations to this include statements that enclose other statements, and statements that end a block of code.

About Tec News

Tec News is optimized for learning Web Development, Programming, Database System and Tutorials, Articles, References for your development. This web help developers, learners learn these technologies easy and free.

Contact Us

If you have any suggestions or have any questions regarding our web please feel free to contact us.

info@tec-news.com        

https://www.tec-news.com