A collection of bits and pieces in PHP
Where am I?
Read all files in directory into array
Set timezone to local
Using mobile or tablet?
exec('pwd',$return); print_r($return);
I couldn’t get scandir working – maybe a problem with permissions? But this one does work …
$dir = 'subdirectory/subsubdir/etc'; $files = []; if ($handle = opendir($dir)) { while (false !== ($entry = readdir($handle))) { if ($entry != "." && $entry != "..") { array_push($files, $entry); } } closedir($handle); }
To set the timezone to Europe/London you need to do this:
<? date_default_timezone_set('Europe/London'); ?>
This function checks to see if the user is using a mobile phone or tablet without the need for media queries in CSS. Was working in 2022.
function isMobileDevice() { return preg_match("/(android|avantgo|blackberry|bolt|boost|cricket|docomo|fone|hiptop|mini|mobi|palm|phone|pie|tablet|up\.browser|up\.link|webos|wos)/i", $_SERVER["HTTP_USER_AGENT"]); } }
Leave a Reply