Search
Left Quote    Black holes are where God divided by zero.
- Steven Wright    
Right Quote
 
[login] | [Register]
 

Simple PHP Tutorial

by: Jester
Page: 1 of 9
(View All)

About PHP and ASP Style Tags

PHP stands for "PHP: Hypertext Preprocessor". Alot of people have been confused by this as the acronym PHP is part of the actual name derived from the acronym.

PHP is a general-purpose scripting language, its ease of use and learning curve make it especially suited to web development and the language can be embedded into HTML, making it relatively easy to produce brilliant, dynamic web pages.

PHP is open source, meaning anyone can download the actual source code and edit it, develop and refine it. PHP is growing at a rapid pace, why don't you give it a try?

For a programmer, PHP may seem very easy to get to grips with. For someone who has just mastered HTML and is looking to write a dynamic website, it may take a little more effort, i have done my best to write an easy-to-follow tutorial. Read onto the next section and get started.


Getting Started

One of the great features of PHP is that it can be embedded into HTML with ease. A PHP document doesn't have to contain PHP code. You could simply write HTML in the document and the server would handle it as HTML. The way you tell the server to invoke PHP to interpret PHP code and return the output to the user is with the PHP tags. Let's have a look.


PHP Mode Tags:

We open "PHP Mode" with the tag. So if we want to write a few lines of HTML code and don't want the trouble of using PHP to output it, we simply close PHP mode and write it as we would any normal HTML webpage. We can jump in and out of PHP mode whenever we want to.


Short Tags

If this feature is enabled in the PHP configuration, we can also use short-style tags to open and close PHP Mode:




This works in exactly the same way as above, it's just easier and shorter to type, a shortcut. Alot of people prefer to use the full tags as above, apparently short-style tags can cause problems when writing XML documents with PHP embedded, the server will become confused and parse code that isn't meant to be PHP code.


ASP-style tags

We can also use ASP-style tags to open and close PHP mode, if this feature is enabled in the PHP configuration file.




This method is rarely used, but it's there if you prefer it.

A Practical Use

If you're new to this, you may be thinking "What the hell is PHP Mode?", let's have a look at a simple HTML document with PHP code embedded into it.




Now as you can see, if we don't open the PHP mode tags, we can just write out the HTML as normal, when we do open into PHP mode we must use only PHP commands, otherwise the server will return a "parsing error". As with Perl almost all lines in PHP end with a semi-colon (;). Remember, your PHP pages will be parsed alot more quickly if you only go into PHP mode when it is necessary. In the above example we use the echo() function, this function is the same as print() in Perl. It just prints out the string between the quotes. not very useful in the above case, but it gives you an idea of the structure of a PHP document. Let's go on and look at variables.



1  |  2  |  3  |  4  |  5  |  6  |  7  |  8  |  9  |  
Next »


No Comments for this page.

You Must be logged in or a member to comment.


Tutorial Stats

Tutorial Stats

230,860 Views
1 Total Comments
3.25 Rating of 5 (4 Votes)

Options

Tutorial Options

· Login to Rate This Article
· Login to Post a Comment
· Read more by this author
Digg This Article! Del.icio.us: Bookmark This Article Reddit: Bookmark This Article BlinkList: Blink This Article! YahooMyWeb BlogMarks: Add This Mark! Furl: Save This Article Spurl: Mark This Article

Articles

Related    

· One File Website
· Pagination with PHP
· Building a Comments Script
· Complete Members System
· Variable Scope



"AllSyntax.com" Copyright © 2002-2017; All rights lefted, all lefts righted.
Privacy Policy  |  Internet Rank