Monthly Archive for September, 2006

PHP Date Format for RFC 3339

The Atom flavored RSS feeds require dates in RFC 3339 format. date() does not currently have anything built in for that. But here’s what it boils down to:

Y-m-dTH:i:sZ

Perl in_array

Perl is frustrating. There is an exists() function that works for hashes, put push() only works for arrays. So I wrote a function to tell me if a string exists in an array.

sub in_array {
  $needle = shift(@_);
  @haystack = @_;
 
  $found = 0;
 
  foreach $hs (@haystack) {
    if ($hs eq $needle) { $found = 1; }
  }
 
  return $found;
 
}
 
@moo = ("one", "two", "three");
if (in_array("two", @moo)) {
  print "two!n";
}