Show DevBest [PHP] Cut string after x characters

Status
Not open for further replies.

Markshall

Русский Стандарт
Contributor
Dec 18, 2010
2,637
2,389
All this does is cuts a string after a certain amount of characters.

Here is the code and I will explain the usage afterwards:

PHP:
function cut( $str, $length )
{
	return ( strlen( $str ) > $length ) ? substr( $str, 0, $length ) . "..." : $str;
}

Usage:
PHP:
$string = "Mark Eriksson is the best and is very sexy";
echo cut( $string, 10 );
//will echo:
//Mark Eriks...
//with the '...'

I coded this for a project I'm making at the moment and thought it may come in handy for people.

Enjoy.
 
Status
Not open for further replies.

Users who are viewing this thread

Top