Pythonic PHP
by admin
Warning: mktime() [function.mktime]: It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'America/Los_Angeles' for 'PDT/-7.0/DST' instead in /home/hemmi3/public_html/blog/inc/_core/_misc.funcs.php on line 870
Warning: date() [function.date]: It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'America/Los_Angeles' for 'PDT/-7.0/DST' instead in /home/hemmi3/public_html/blog/inc/_core/_misc.funcs.php on line 981
Warning: date() [function.date]: It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'America/Los_Angeles' for 'PDT/-7.0/DST' instead in /home/hemmi3/public_html/blog/inc/_core/_misc.funcs.php on line 986
Warning: date() [function.date]: It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'America/Los_Angeles' for 'PDT/-7.0/DST' instead in /home/hemmi3/public_html/blog/inc/_core/_misc.funcs.php on line 986
Warning: date() [function.date]: It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'America/Los_Angeles' for 'PDT/-7.0/DST' instead in /home/hemmi3/public_html/blog/inc/_core/_misc.funcs.php on line 987
Warning: date() [function.date]: It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'America/Los_Angeles' for 'PDT/-7.0/DST' instead in /home/hemmi3/public_html/blog/inc/_core/_misc.funcs.php on line 988
on Jun.28, 2011,under Computers, Programming
Warning: date() [function.date]: It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'America/Los_Angeles' for 'PDT/-7.0/DST' instead in /home/hemmi3/public_html/blog/inc/sessions/model/_hit.class.php on line 901
I shot some photographs for a friend and put them in an open dir for himto grab them. NO big deal, but he mailed me that he'd rather see the images in the folder.
I did that before at least twice. This time I decided to grab an exiting script. I found http://www.phpace.com/image-resizing-with-php/ by Sam Yapp. The script scans the folder fot images, creates thumbs with the GD library and displays them.
I liked two lines of code because they feel so Pythonic. This is the first:
preg_match('#^(.+?)(_t)?\.(jpg|gif|png)#i',
$entry->getFilename(), $matches) );
list( ,$name, $is_a_thumb, $extension) = $matches;
If you look beyond the regular expression, at least if you're intimidated by them, the array $matches collects matches from the regex. $matches[0] is the complete match consisting of the filename of an image. $matches[1] contains the first part (before the dot) of the filename, $matches[2] contains '_t' if it's there (thumbnails are created with an added _t in the filename) and $matches[3] contains the part after the dot.
Interesting is the list constructor in the second line of the example code. That's the Pythonic part. It creates all the variables in one line. Or am I mistaken and is it Perl magic in origin?
That's not all there is. You see the $entry->getFileName(). That comes from this code:
$dir = new DirectoryIterator($path);
foreach( $dir as $entry ){
Wow. An iterator in PHP. I hadn't seen this in PHP before. I have in Python though. hte DirectoryIterator seems pretty complete. PHP is growing up.
Warning: date() [function.date]: It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'America/Los_Angeles' for 'PDT/-7.0/DST' instead in /home/hemmi3/public_html/blog/inc/items/model/_itemquery.class.php on line 628
Warning: date() [function.date]: It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'America/Los_Angeles' for 'PDT/-7.0/DST' instead in /home/hemmi3/public_html/blog/inc/items/model/_itemquery.class.php on line 628



Feedback awaiting moderation
This post has 1 feedback awaiting moderation...
Leave a comment