Page 194 - Beginning PHP 5.3
P. 194
Part II: Learning the Language
But think not that this famous town has
only harpooneers, cannibals, and
bumpkins to show her visitors. Not at
all. Still New Bedford is a queer place.
Had it not been for us whalemen, that
tract of land would this day perhaps
have been in as howling condition as the
coast of Labrador.
END_TEXT;
echo “<h2>The text:</h2>”;
echo “<div style=\”width: 30em;\”>$myText</div>”;
$myText = preg_replace( “/[\,\.]/”, “”, $myText );
$words = array_unique( preg_split( “/[ \n\r\t]+/”, $myText ) );
usort( $words, create_function( ‘$a, $b’, ‘return strlen($a) - strlen($b);
’ ) );
echo “<h2>The sorted words:</h2>”;
echo “<div style=\”width: 30em;\”>”;
foreach ( $words as $word ) {
echo “$word “;
}
echo “</div>”;
?>
</body>
</html>
Figure 7-5
156
9/21/09 9:00:56 AM
c07.indd 156
c07.indd 156 9/21/09 9:00:56 AM