Return to Snippet

Revision: 48672
at July 7, 2011 14:15 by alyssonweb


Initial Code
if ( ! function_exists( 'to_friendly_string' ) ) :
	
	function to_friendly_string( $phrase = '', $maxLength = false ) {
		if ( empty( $phrase ) )
			return '';
			
		$result = strtolower( $phrase );
		
		$result = trim( preg_replace( "/&{1}(amp;)?/", ' and ', $result ) );
		$result = trim( preg_replace( "/[^a-z0-9\s-]/", '', $result ) );
		$result = trim( preg_replace( "/[\s-]+/", ' ', $result ) );
		
		if ( $maxLength ) 
			$result = trim( substr( $result, 0, $maxLength ) );
			
		$result = preg_replace( "/\s/", "-", $result );

		return $result;
	}
	
endif;

Initial URL

                                

Initial Description
Convert a string to friendly string.

Initial Title
To Friendly String

Initial Tags
url

Initial Language
PHP