This is a discussion on Basics of PHP within the Programming Articles forums, part of the Webmaster Articles/Tutorials category; This tutorial is for first time PHP users and will teach you the basics of creating a simple PHP page ...
| |||||||
| Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| | #1 (permalink) |
| WMT Addict | This tutorial is for first time PHP users and will teach you the basics of creating a simple PHP page that assigns values to variables and then displays them onto the browser. First off, load up a text editor such as notepad. All PHP coding must be surrounded by the php opening and closing tags which are: <?php CODE HERE ?> And any page you save that contains php must be saved with the extension of .php E.G. "index.php" "content.php". They are the basics of starting and closing php pages and saving them, now for the basic coding. All php variables beging with a dollar sign($). There are some rules with using variables though. 1)Start with a dollar sign 2)You must follow the dollar sign with an underscore(_) or a letter, this letter can however be uppercase or lowercase. 3)You can have as many characters as you like but don't go over the top, in some scripts you create you might be having to typing it numerous times so this could get tedious with long variable names. Here are some examples of VALID variables: $width $result $_result $_x So now we know the rules on making variables below is how you assign a value. Assigning values to a variable is very simple all you do is: $result = 'the variables contents here'; Every line of PHP code has to end with a semi-colon! Otherwise it will produce errors in the PHP Syntax. Below are examples of setting variables with values: $result = '123'; $_x = 'I like PHP'; $RESULT = 'This is different to the variable named result'; Now to learn how to display the variables (and normal text). To display text on the screen you need to use the echo function. To use this simply imbetween the opening and closing tags echo "YOUR TEXT HERE"; REMEMBER THE SEMI-COLON AT THE END OF THE LINE! Although displaying variables is different. Below are examples of different ways to displaying variables: echo "SOME TEXT HERE". $variable ."SOME MORE TEXT HERE"; echo $variable ."TEXT HERE"; echo "TEXT HERE". $variable; echo $variable; Now you just upload all of this to a PHP webserver and you are done. Have questions? PM me or post it here on the forums. |
| | |
| Tags |
| basics, php |
| Thread Tools | |
| Display Modes | |
| |
| ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| User System Basics | mck9235 | Programming / Scripting / Coding | 3 | 15-04-2005 20:31 |
| Website Accessibility - The Basics | Wistow | Website Design Articles | 0 | 19-03-2005 15:52 |