PHP Programming/Code Snippets

< PHP Programming

Code snippets are useful for any beginners to learn code from.

PHP 4 & 5

Basic Level

Bobby

$var

Joshua fit the battle of Jericho.

Again, if single quotes were used — 'Joshua fit the battle of $var'; — this would output:

Joshua fit the battle of $var.

1214

PHP 4

Basic Level

<?php
  $variable1 = 'beginning';
  //This is a comment after a variable being defined
  if ($variable1 == 'beginning') {
    //If is a test to see if a variable has certain
    //value and initiates the wanted sequences if true
    echo 'Hello World!';
    //The echo displays to the page
  }
else
{
echo 'some code';
}

?>

OOP

Include OOP based examples, made by experienced developer

PHP 5 Only

Basic Level

Basics, working only on PHP 5.

E.g. file_put_contents("filename", "Text to save"); will write Text to save to filename, but will overwrite existing text whereas file_put_contents("filename", "Text to save", FILE_APPEND); will write Text to save to filename, but will not overwrite existing text (instead it appends).

OOP

  1. Input validation by Kgrsajid.
  2. Advanced Input validation by nemesiskoen.
This article is issued from Wikibooks. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.