$num_words ) && ( $num_words > 0 ) ) { $phrase = implode( ' ', array_slice( $phrase_array, 0, $num_words ) ).$read_more; } return $phrase; } /** * Shortcut to determine whether one string is found within another. * * @param string $haystack * @param string $needle * @return boolean */ public static function contains( $haystack, $needle ) { return ( strpos( $haystack, $needle ) !== false ); } /** * Shortcut to determine whether one string starts with another. * * @link http://stackoverflow.com/questions/834303/startswith-and-endswith-functions-in-php * @param type $haystack * @param type $needle * @return boolean */ public static function starts_with( $haystack, $needle ) { return $needle === '' || strpos( $haystack, $needle ) === 0; } /** * Shortcut to determine whether one string ends with another. * * @link http://stackoverflow.com/questions/834303/startswith-and-endswith-functions-in-php * @param type $haystack * @param type $needle * @return boolean */ public static function ends_with( $haystack, $needle ) { return $needle === '' || substr( $haystack, -strlen( $needle ) ) === $needle; } /** * Generates 'lorem ipsum' text. * * @return string */ public static function lorem() { return 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor '. 'incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud '. 'exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure '. 'dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. '. 'Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt '. 'mollit anim id est laborum.'; } /** * Trims the beginning of a string of a given string. The start of the * haystack must be an exact match of the needle for this to work. * * @link http://stackoverflow.com/questions/4517067/remove-a-string-from-the-beginning-of-a-string * @param type $haystack * @param type $needle * @return If the needle was found, then the new haystack; otherwise, the old haystack */ public static function trim_start( $haystack, $needle ) { if ( substr( $haystack, 0, strlen( $needle ) ) == $needle ) { return substr( $haystack, strlen( $needle ) ); } return $haystack; } /* PRIVATE */ /** * Only use this class as a utility.. */ private function __construct() { // Intentionally blank.. } } ?>