php
Nov 4, 2017
PHP 7.0 (and 5.6) on the same pc
sudo add-apt-repository ppa:ondrej/php
sudo apt-get update
sudo apt-get install php7.0 php5.6 php5.6-mysql php-gettext php5.6-mbstring php-mbstring php7.0-mbstring php-xdebug libapache2-mod-php5.6 libapache2-mod-php7.0Switch PHP version:
From php5.6 to php7.0:
Apache:
sudo a2dismod php5.6 ; sudo a2enmod php7.0 ; sudo service apache2 restartCLI:
Jan 11, 2017
Generate a random string A-Z, 0-9 in PHP
<? php
$length = 10;
$randomString = substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, $length);
echo $randomString;
?>
/* Defining the function */
function pwgen ($len) {
/* Variables declaration */
$pw = "";
$wordBook = array ();
/* Fill array with printable english characters */
for ( $wb=33; $wb<127; $wb++ ) {
array_push ( $wordBook, $wb );
}
shuffle ( $wordBook ); // Shake
$pass = array_rand ( $wordBook , $len ); // Slice a part
shuffle ( $pass ); // Shake again
/* Save the array into variable */Oct 19, 2016
Sent email & attachment
<?php
$path = "path/to/file/"; // path to file
$filename = "file.fta"; // file to attachAug 15, 2016
Array to String PHP?
$string = implode('|',$array);implode — Join array elements with a string
Aug 15, 2016
Calculate age based on date of birth with PHP
<?php
# object oriented
$from = new DateTime('1972-12-11');Jul 26, 2016
The tricky "sprintf"
string sprintf ( string $format [, mixed $args [, mixed $... ]] )More info: http://php.net/manual/en/function.sprintf.php
Function Reference/esc url
Jun 20, 2016
Set Cookie and trigger content based on it.
Example setcookie() send:
