Php: Difference between revisions
Jump to navigation
Jump to search
Adamcolton (talk | contribs) |
Adamcolton (talk | contribs) |
||
| (7 intermediate revisions by the same user not shown) | |||
| Line 6: | Line 6: | ||
== Error Log == | == Error Log == | ||
cat /var/log/apache2/error.log | cat /var/log/apache2/error.log | ||
sudo truncate -s 0 /var/log/apache2/error.log | |||
cat /var/log/apache2/error.log && sudo truncate -s 0 /var/log/apache2/error.log | |||
== Dates and Times== | == Dates and Times== | ||
| Line 11: | Line 13: | ||
date('Y-m-d') //mysql date | date('Y-m-d') //mysql date | ||
time() returns current unix time | time() returns current unix time | ||
strtotime($str) | |||
== Arrays == | == Arrays == | ||
array_key_exists(key,array); | array_key_exists(key,array); | ||
array_merge | |||
To remove a by key | |||
unset($arr[$key]); | |||
== JSON == | == JSON == | ||
| Line 27: | Line 34: | ||
Write string to file. | Write string to file. | ||
== Classes == | |||
class Foo{ | |||
public function __construct(){ | |||
... | |||
} | |||
} | |||
== Magic Methods == | |||
* __get | |||
* __set | |||
* __call | |||
[[Category:Notes]] | [[Category:Notes]] | ||
[[Category:Code]] | [[Category:Code]] | ||
Latest revision as of 00:49, 12 May 2016
Misc.
- count($arr) : returns array length
- join($glue, $arr)
- is_null($foo)
Error Log
cat /var/log/apache2/error.log sudo truncate -s 0 /var/log/apache2/error.log cat /var/log/apache2/error.log && sudo truncate -s 0 /var/log/apache2/error.log
Dates and Times
date('Y-m-d H:i:s') //mysql datetime
date('Y-m-d') //mysql date
time() returns current unix time
strtotime($str)
Arrays
array_key_exists(key,array); array_merge
To remove a by key
unset($arr[$key]);
JSON
json_decode($str, true); json_encode($obj);
The true makes it associative.
Files
readfile($filename);
Ouputs the file to stdOut.
file_put_contents($filename, $str);
Write string to file.
Classes
class Foo{
public function __construct(){
...
}
}
Magic Methods
- __get
- __set
- __call