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 Code | Description |
---|---|
\n | New Line |
\r | Carriage Return |
\t | Tab |
\b | Backspace |
\' | Single Quote |
\“ | Double Quote |
\\ | Backslash |
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';
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");
Identify variable type
var_dump($variableName);
Add to array
$array[sizeof($array)] = 'newValue';
Boolean entry
$var = true;
Evaluate False | Evaluate True |
---|---|
boolean false 0 0.0 ” “ “0” NULL | Everything else |
Float entry
$normalNumber = 1.5; $hugeNumber = 1.5E10; $tinyNumber = 1.5E-10;
$val = 99; //base 10 $val = 077; //base 8 (63) $val = 0xf; //base 16 (15)
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;