Good Old sscanf

February 28, 2008 on 6:06 am | In PHP | No Comments

Working in PHP, all this time, and the big uses you find in regex, and all the string processing we need to, could make us forget our old friend that can easily solve a problem.
sscanf, do you remember it, well, for quite some time I didn’t, until I saw it in a random code I found online, so this post is a reminder that this function exists.
An example, if we have a date, lets say coming from a Mysql DB, (ofcourse you can use strtotime, but sometimes it has it’s limitations) and you want to get the year, month, day, hour, minutes, and seconds, and you have it in a string, you can parse it with some splits, but 1 call of sscanf can do the job.

<?php
$date = ‘2007-05-18 22:15:03′;
sscanf($date,‘%d-%d-%d %d:%d:%d’,$y,$m,$d,$h,$i,$s);
var_dump($y,$m,$d,$h,$i,$s);

and thats all.

PHP5 CAPTCHA

February 16, 2008 on 3:19 pm | In Free Software & Open Source, PHP, Releases | No Comments

I’ve written a small CAPTCHA library, in an OO style, and I love to share it with you
http://sourceforge.net/projects/php5captcha/

Powered by WordPress with Pool theme design by Borja Fernandez.
Entries and comments feeds. Valid XHTML and CSS. ^Top^