Skip to content

Instantly share code, notes, and snippets.

@robwilkerson
robwilkerson / Intelligent Indefinite Articles
Created October 3, 2011 11:58
Attempts to intelligently use "a" and "an" in a sentence.
$l = array( 'a apple is a fruit', 'a banana is also a fruit' );
foreach( $l as $s ) {
$s = preg_replace( '/(^| )a ([aeiouAEIOU])/', '$1an $2', $s );
echo $s . "\n";
}
# outputs
an apple is a fruit
a banana is also a fruit
@robwilkerson
robwilkerson / set-extract-non-empty.php
Created September 27, 2011 13:33
CakePHP: Remove empty array elements at any level.
/**
* Removes items from an array where key information is missing. Useful in
* dynamic add situations.
*/
$this->data['Date'] = Set::extract( '/Date[start=/\S+/][end=/\S+/]/.', $this->data );