Archive for the ‘php’ Category

Twitter feed on my homepage

Wednesday, November 4th, 2009

Went at it again with my cron-powered PHP jobs, this time for putting my Twitter timeline on my homepage. Complete with little bird.

Twitter on the homepage

This is replacing the Friendfeed blog+twitter entries that appeared previously because:

  1. I love playing with new APIs. The T one will be my third personal API integration. Did FF and Flickr prior.
  2. I’ll tweet the better blog entries, so I don’t need a merged blog+twitter feed. Just Twitter is fine.
  3. FF is a second-hand tweet, why not get it first-hand?
  4. FF has great features, but I feel closer to T.  When I had FF on a bunch of different social services it was more worthwhile for the merging of the feed.  But I’ve since whittled it way down.

My PHP cron job is aided by TwitterLibPHP by Justin Poliey.

Flickr photos on my website

Monday, October 19th, 2009

It’s been on my mind for a while, got it partially implemented a couple weeks back, and today I finally finished it: my Flickr pics on my homepage.

I recently decided to make Flickr the primary place I upload personal photos. Facebook used to be the primary place to upload, but frankly, I’d rather have people going to my website than Facebook for my activity, and I’m not interested in being in front of people constantly, if much at all.  Where better to not be noticed than on your own site.

One day I got a wild hair to start a picture-a-day project on Flickr called “365″. That restarted my interest in showing the pictures on my site.  And I just enjoy playing with API’s.  Especially well-done ones like Flickr’s.

To get the pics showing, a cron job runs every night that uses the Flickr API to build a javascript file that my homepage calls whenever people visit. The response from the API takes too long to tie it directly to my website; best to have a little static file just ready to go whenever. So there’s a javascript data file made every night, then a javascript controller and CSS for the web page that puts it all together. And the jQuery library eases the javascript code as usual.

27. Flickr on my homepage

I’d imagine this is the most sensible approach. If you have a better way, please tell me in the comments here.

It would be nice to incorporate a “Set” selector someday.  Good enough for now. :)

PHP filter_var, where have you been all my life?

Saturday, January 17th, 2009

Stumbled on something handy that I can’t believe I’m just now finding.  Gotta love PHP convenience, including this built-in way to validate form input.

PHP filter_var

Thanks again, NETTUTS (tutorial here).

if (isset($_POST['email'])) {
$email = filter_var($_POST['email'], FILTER_SANITIZE_EMAIL);
if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
echo "$email is a valid email address.";
} else {
echo "$email is NOT a valid email address.";
}
}
// also FILTER_SANITIZE_URL, FILTER_VALIDATE_URL