User Tools

Site Tools


php_programming_reference

PHP 5.0 Reference

Classes

Definition

class Name
{
  var $someVariable;
  var $anotherVariable;
 
  //Constructor (same name as class)
  function Name($varOne, $varTwo)
  {
    $this->someVariable = $varOne;
    $this->anotherVariable = $varTwo;
  }
 
  //some function
  function test()
  {
    return $this->someVariable;
  }
}

Escape Sequences

Escape Code Description
\nNew Line
\rCarriage Return
\tTab
\bBackspace
\'Single Quote
\“Double Quote
\\Backslash

SimpleXML

Create/Load

Create XML element

$xml = new SimpleXMLElement();
//or
$xml = new SimpleXMLElement($content);

Load XML file

$xml = simplexml_load_file('file.xml');

Save a file

$xml->asXML('test.xml');

Add a Child

$node = $xml->addChild('child name');
//or
$node = $xml->addChild('child name', 'content');

Remove a Child

unSet($xml->node[0]);
//or
unSet($xml->node['name']);

Add an Attribute

$node->name['attribute name'] = 'value';

Time

Current time in Unix timestamp

time();

Convert Unix timestamp to readable date

strftime("%Y.%m.%d", $unixTimestamp);

Convert English timestamp to Unix

strtotime("date string");

Variables

Types

Identify variable type

var_dump($variableName);
Arrays

Add to array

$array[sizeof($array)] = 'newValue';
Boolean

Boolean entry

$var = true;
Evaluate False Evaluate True
boolean false
0
0.0
” “
“0”
NULL
Everything else
Float

Float entry

$normalNumber = 1.5;
$hugeNumber = 1.5E10;
$tinyNumber = 1.5E-10;
Integer
$val = 99; //base 10
$val = 077; //base 8 (63)
$val = 0xf; //base 16 (15)
String

Declaration

$string = 'Enclosed in single or double quotes.';

Inclusion in a string

$moreText = "more text in it";
$string = "This is some text with ${moreText}.";

Multi-line string entry

$longString = <<<string
This is the first line.
This is the second line.
This is the last line.
string;
php_programming_reference.txt · Last modified: 2010/12/04 21:33 (external edit)