Ok as request by people i have written a brief introduction to php which if read properly should get you on the road :p
The tutorial has taken me just over 2 days to write so i hope you appriciate it. Would love Rep if you like it
PHP - Syntax
----Syntax - The rules that must be followed to write properly structured code.
PHP's syntax are similar to most other programming languages (C, Java, Perl) with the addition that all PHP code is contained with a tag, of sorts. All PHP code must be contained within the following...
If you are writing PHP scripts and plan on distributing (Selling) them, I suggest that you use the standard form (which includes the ?php) rather than the shorthand form. This will ensure that your scripts will work, even when running on other servers with different settings.Code:<?php ?> or the shorthand PHP tag that requires shorthand support to be enabled on your server... <? ?>
How to Save Your PHP Pages
If you have PHP inside your HTML, and you want the web browser to display it correctly you must save the file as .php instead of .html. So be sure to check that you are saving your files correctly. Instead of index.html, it should be index.php if there is PHP inside included in the file.
Example Simple HTML & PHP Page
Below is an example of one of the easiest PHP and HTML page that you can create and still follow web standards.
If you save this file and place it on PHP enabled server then you should see "Hello Liam!" displayed. If not, please check that you followed my example correctly.Code:<html> <head> <title>My First PHP Page</title> </head> <body> <?php echo "Hello Liam!"; ?> </body> </html>
I used the PHP function echo to write Hello World and we will be talking in greater depth about this PHP function and others, later on in this or later tutorials (If i get around to writing them :p).
The Semicolon!
As you may or may not have noticed in the above example, there was a semicolon after the line of PHP code. The semicolon is the end of a PHP statement and should never be forgotten. For example, if I repeated "Hello Liam!" several times, then I would need to place a semicolon at the end of each statement.
White Space
As with HTML, whitespace is ignored between lines of code. This means it is OK to have one line of PHP code, then 20 lines of blank space before the next line of PHP code.
Example:
[OK next is variables if you are not already lost then great continue to the next bit but if you require help with any of the above please PM me and i will help you the best i can.]Code:<html> <head> <title>My First PHP Page</title> </head> <body> <?php echo "Hello World!"; echo "Hello World!"; ?> </body> </html>
PHP - Variables
f you have never had any programming, Algebra, or scripting experience, then the concept of variables will be a new to you.
A variable is a means of storing a value, such as text string "Hello World!" or the integer value 4. A variable can then be reused throughout your code, instead of having to type out the actual value, over and over again.
In PHP you define a variable with the following form:
$variable_name = Value;
If you forget that dollar sign at the beginning, it will not work. This is a common mistake for new PHP programmers!
A Quick Variable Example
Say that we wanted to store the values that I talked about in the above paragraph. How would I go about doing this? We would first want to make a variable name and then set that equal to the value we want. See my example below for the correct way to do this.
[As you may have noticed this is a long tutorial but is worth it :p. If you start to get bored dont forget this will always be here you can remember where you are then go out for a bit then come back. It is better to have breaks in between as it helps you to take more inCode:<?php $hello = "Hello World!"; $a_number = 4; ?>]
PHP - Echo
As you saw in the previous lesson, the PHP function echo is a means of outputting text to the web browser. Throughout your PHP career you will be using the echo function more than any other.
Outputting a String
To output a string use the PHP echo function. You can place either a string variable or you can use quotes, like I have done below, to create a string that the echo function will output.
In the above example I output Hello! without a hitch. To review, this text we are outputting is being sent to the user as a web page, so it is important that we use proper HTML syntax!Code:<?php echo "Hello!"; echo "<h5>I love Liam :p</h5>"; ?>
In the second line I used echo to write a valid Header 5 HTML statement! To do this I simply put the <h5> at the beginning of the string and closed it at the end of the string. Just because you're using PHP to make web pages does not mean you can forget about HTML syntax! HTML plays a big part in most PHP coding. For example Habboxforum May look like a snazzy php full vbulletin but if you have ever saw a vbulletin file you would see a great deal of HTML coding mixed with PHP.
Be Careful When Echoing Quotes!
It is pretty cool that you can output HTML with PHP. However, you must be careful when using HTML code or any other string that includes quotes! The echo function uses quotes to define the beginning and end of the string, so you must use one of the following tactics if your string contains quotations:
* Don't use quotes inside your string
* Escape your quotes that are within the string with a slash. To escape a quote just place a slash directly before the quotation mark, i.e. \"
* Use single quotes (apostrophes) for quotes inside your string.
See my example below for the right and wrong use of the echo function:
Echoing VariablesCode:<?php echo "<h5 class="specialH5">I love Liam!</h5>"; // This won't work because of the quotes around specialH5! echo "<h5 class=\"specialH5\">I love Liam!</h5>"; // OK because we escaped the quotes! echo "<h5 class='specialH5'>I love Liam!</h5>"; // OK because we used an apostrophe '. ?>
Echoing variables is easy. The PHP developers put in some extra work to make the common task of echoing all variables nearly foolproof! No quotations are required, even if the variable does not hold a string. Below is the correct format for echoing a variable.
OutPut:Code:<?php $my_string = "Hello HBF Members. My name is: "; $my_letter = Liam; echo $my_string; echo $my_letter; ?>
Part 2 to this MASSIVE tutorial will be up sometime tomorrow. Getting late now and been working all day so i need some sleep :pCode:Hello HBF Members. My name is:Liam
Thanks for reading hope you learned something from this part
Thread closed by ,Jess, (Forum Super Moderator): Due to bump.






]








