You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

PHP.md 2.3 KiB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. This is a quick introduction to PHP, which will be expanded on
  2. (eventually).
  3. ## What is PHP?
  4. **P**HP **H**yper-text **P**re-Processor. Allows web developers to write
  5. dynamically generated pages quickly. With synergy!
  6. PHP manual: <http://ie.php.net/manual/en/>
  7. ## Basic PHP
  8. * cd to your \~/public_html folder on Redbrick.
  9. `cd ~/public_html`
  10. * Create a file called *hello.php* using a text editor.
  11. `nano hello.php`
  12. * Type this PHP code into the file
  13. `<?php`\
  14. `echo "Hello World!";`\
  15. `?>`
  16. * Save and exit (CTRL + O, CTRL + X)
  17. <!-- -->
  18. * Set correct permissions for the php file (this must be done for
  19. every .php file you want to use).
  20. `chmod 700 hello.php`
  21. * Visit www.redbrick.dcu.ie/\~username/hello.php to view your
  22. script\'s output.
  23. <!-- -->
  24. * It should display “Hello World!” in plain text within your
  25. browser.
  26. ## The include() function
  27. Without understanding much about the details of PHP, you can save
  28. yourself a great deal of time with the use of the PHP include function.
  29. The include function takes a file name and simply inserts that file\'s
  30. contents into the script that calls the include function. (Ref:
  31. tizag.com)
  32. menu.php
  33. <a href="http://www.example.com/index.php">`Home`</a>`-`\
  34. <a href="http://www.example.com/about.php">`About Us`</a>`-`\
  35. <a href="http://www.example.com/links.php">`Links`</a>`-`\
  36. <a href="http://www.example.com/contact.php">`Contact Us`</a>
  37. index.php
  38. <html>
  39. <body>
  40. `<?php include("menu.php"); ?>`\
  41. </body>
  42. </html>
  43. Where you inserted “include(“menu.php”);” the contents of
  44. menu.php are included into index.php at that location. When you add or
  45. remove pages from your website, you only need to update one file,
  46. menu.php, in order to display a link on every page in your website that
  47. includes menu.php.
  48. ## Variables
  49. Like any decent programming language, PHP uses variables.
  50. PHP variables can store any data you wish. They start with a \$ sign and
  51. contain alphanumerical characters, but must always start with a letter.
  52. `$example1 = "example";`\
  53. `echo $example1;`
  54. This will output the text \"example\".
  55. Variables as the name suggest can be altered after they\'re declared.
  56. `$example1 = "altered example";`
  57. \$example1 now contains \"altered example\" and the previous contents
  58. are gone.
  59. [Category:Helpdesk](/Category:Helpdesk "wikilink")