To Remove empty array elements in PHP you can use the array_filter method.
Sample PHP
array_filter($inputArray)
To Remove empty array elements in PHP you can use the array_filter method.
array_filter($inputArray)
To get current Year in PHP you can simply use the following method.
<?php echo date("Y"); ?>
To calculate PercentOf in PHP you can use the following snippet. It will calculate the percent of 2 given integers.
Function PercentOf($int1, $int2) { if ($int2 <= 0 || $int1 <=0){ return 0; } $val1 = $int1 / $int2; $retVal = $val1 * 100; return $retVal; }
If there is a 0 passed it will return 0.
To replace blanks in a string in PHP you can use the following snippet.
$stringOne = "This is a Test!"; $stringTwo = str_replace(" ", "", $stringOne);
To Decode a URL in PHP you can use the following snippet.
Also take a look at How to encode a URL in PHP.
urldecode("http://codesnippets.fesslersoft.de/")
To encode a URL in PHP you can use the following snippet.
Also take a look at How to decode a URL in PHP.
urlencode("http://codesnippets.fesslersoft.de/")
To get the size of a file in PHP you can use the following snippet.
You can combine this snippet with How to convert bytes to human readable file size in PHP.
$MyFileSize = filesize('fileName');
To create a folder in PHP you can use the following snippet.
mkdir('folderName');
To make a random number in PHP you can use the following snippet.
$randInt = rand(9); // make a random number between 0 and 9
To set the server time in PHP you can use the following snippet.
It required PHP 5.1.0 or higher.
date_default_timezone_set('Europe/Berlin');
for more informations see: date_default_timezone_set and for a list of possible Timezones List of Supported Timezones