I have all these PHP snippets on my desk of things I learned taking Linkedin Learning PHP courses. I took a 4-hr long coding test for a remote PHP/LAMP Developer job with the Huntsville, AL branch of NASA. I was excited for the opportunity, but learning I was lacking on all kinds of modern programming techniques, including the ubiquitous arrow function, which was present in both PHP and JavaScript ES8.
That was in February. But, aside from the new concepts, I discovered I was also greatly in need of a refresher in the whole workflow of LAMP web development. Things I used to know and work with daily at Bookit.com (2011) were now foreign and distant to me.
With a little refresher course in fundamentals and a lot of practice I knew it would all come back to me. And it did. I was writing basic PHP single-file programs in no time!
The Code
The following are notes on different PHP functions, syntax, variables, and techniques that were important enough for me to write down. I’m aggregating them here to get them off my desk, help me remember them by having them all in one easily findable place (the internet), and also, hopefully, to help you on your journey to learning PHP and LAMP development concepts.
Leave a comment if you have a question and I’ll do my best to reply quickly!
<?php $dir = new DirectoryIterator('common'); foreach ($dir as $file) { echo $file . '<br>"; }
// SPLFileInfo() getSize() - File size in bytes getATime() - Last accessed time (unix timestamp) getMTime() - Last modified getExtension() getType() - File, symlink, or dir
is_file() function VS isFile() class method
// Basic PHP 7 project folder structure basic_php_project/ public/ index.php images/ css/ private/ initialize.php functions.php shared/
mysqli_connect ( $host, $user, $password, $database ); mysqli_close($conn);
Callback_Filter() // requires PHP 5.3 or greater
<?php $courses = simpleXML_load_file('/path/courses.xml'); // $courses = new SimpleXMLIterator;? foreach ($courses as $course) { $matches = new RegexIterator( $course->author, '/joh?n peck/i'); foreach ($matches as $match) { echo $course->title . ' with ' . $match . '(Durations: ' . $course->duration . ')<br>'; } }
if (isset ($_POST['download'])) { $titles = array_keys ($rates[0]); $file = new SplTempFileObject(); $foreach ($rates as $currency) { $file>fputcsv($currency); } } $file->rewind();
Date Published: 04/26/21