Beginners PHP Tutorial

10,015 views

Published on

Published in: Technology
1 Comment
5 Likes
Statistics
Notes
No Downloads
Views
Total views
10,015
On SlideShare
0
From Embeds
0
Number of Embeds
193
Actions
Shares
0
Downloads
613
Comments
1
Likes
5
Embeds 0
No embeds

No notes for slide

Beginners PHP Tutorial

  1. 1. A beginners tutorial in PHP
  2. 2. Step 1: <ul><li>To use PHP you’ll need a server to work on and test your page… </li></ul><ul><li>You may already have web space with PHP installed to work on, </li></ul><ul><li>Or you may already have a server installed on your system, </li></ul><ul><li>If not you’ll need to install one yourself…. </li></ul>
  3. 3. Installing a server: <ul><li>An easy way to aquire an Apache server, along with PHP and MySQL built in (you’ll need these when using PHP), is using </li></ul><ul><li>WAMP (Windows) or, </li></ul><ul><li>MAMP (Mac) ( http:// www.mamp.info ) </li></ul><ul><li>LAMP (Linux) </li></ul><ul><li>You can download WAMP at http://www.wampserver.com/en/ </li></ul>
  4. 4. Step 2: <ul><li>Once you have followed the online instructions for installing and configuring WAMP, you need to check it works! </li></ul><ul><li>Open notepad (php can be added straight into your html) and type: </li></ul><ul><li><html> </li></ul><ul><li><head> </li></ul><ul><li><title>PHP Test</title> </li></ul><ul><li></head> </li></ul><ul><li><body> </li></ul><ul><li><?php echo '<p>Hello World</p>'; ?> </li></ul><ul><li></body> </li></ul><ul><li></html> </li></ul>
  5. 5. Testing: <ul><li>Save this as ‘hello.php’ in your ‘www’ folder located within your WAMP folder. </li></ul><ul><li>This can be done by selecting ‘all files’ when saving rather than the default ‘.txt’ </li></ul><ul><li>(Note: you can also just type this script straight into a new document in Dreamweaver if preferred) </li></ul><ul><li>Now preview by opening your browser and entering http://localhost/hello.php </li></ul><ul><li>Your page should look like this… </li></ul>
  6. 7. Step 3: Variables <ul><li>Variables will allow a value to be changed throughout your page without having to go through and find it every time you need it changed. </li></ul><ul><li>A variable can be defined by using ‘$’ at the beginning of your variable name. e.g. $variable = ‘value’ </li></ul><ul><li>A variable must start with a letter or underscore and can only contain letters, numbers or underscores, and must not use spaces </li></ul>
  7. 8. Variables: a simple example <ul><li><html> </li></ul><ul><li><head> </li></ul><ul><li><title>PHP Test</title> </li></ul><ul><li></head> </li></ul><ul><li><body> </li></ul><ul><li><?php </li></ul><ul><li>$weather=&quot;sunny&quot;; </li></ul><ul><li>echo 'Hello World it’s '; </li></ul><ul><li>echo $weather; </li></ul><ul><li>?> </li></ul><ul><li></body> </li></ul><ul><li></html> </li></ul><ul><li>Note: every line of PHP must end in ‘ ; ’ </li></ul>
  8. 9. The result should look like this:
  9. 10. Now to experiment! <ul><li>For more information on PHP and the next steps in learning syntax why not try: </li></ul><ul><li>http://www.w3schools.com/PHP/php_string.asp </li></ul><ul><li>http://www.webmonkey.com/tutorial/PHP_Tutorial_for_Beginners#Basic_Syntax </li></ul><ul><li>http://www.developphp.com/ </li></ul>
  10. 11. The End.

×