I just really want to copy and paste the code from that presentation.
Yes, I'm still using PHP.
I just really want to copy and paste the code from that presentation.
Yes, I'm still using PHP.
<?php | |
// Short Ternary Operators | |
$var = 'SomeValue'; | |
$output = $var ? $var : 'default'; | |
$output = $var ?: 'default'; // PHP >= 5.3 | |
// Directory Listing #3 | |
$dir = 'application/modules/'; | |
foreach(new DirectoryIterator($dir) as $fileInfo) { | |
echo "Filename is: " . $fileInfo->getFilename(); | |
} | |
// Exploded String values | |
$string = 'bazinga.foo.bar.suitup'; | |
$values = explode('.', $string); | |
$sheldon = $values[0]; //bazinga | |
$barney = $values[3]; //suitup | |
list($sheldon, , , $barney) = explode('.', $string); | |
// PHP 5.4 stuff | |
$sheldon = explode('.', $string)[0]; | |
$barney = explode('.', $string)[3]; | |
// File Path Information | |
$path = '/some/directory/in/filesystem/file.some.txt'; | |
$fileInfo = pathinfo($path); | |
$fileInfo['dirname'] === pathinfo($path, PATHINFO_DIRNAME); | |
$fileInfo['basename'] === pathinfo($path, PATHINFO_BASENAME); | |
$fileInfo['extension'] === pathinfo($path, PATHINFO_EXTENSION); | |
$fileInfo['filename'] === pathinfo($path, PATHINFO_FILENAME); | |