note 115183 deleted from function.strlen by cmb

From: Date: Sun, 25 Jul 2021 14:16:25 +0000
Subject: note 115183 deleted from function.strlen by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-216653@lists.php.net to get a copy of this message
Note Submitter: vaqasuddin ---- function limit_text( $text, $limit = 100000000000 ) { if ( strlen ( $text ) < $limit ) { return $text; } $split_words = explode(' ', $text ); $out = null; foreach ( $split_words as $word ) { if ( ( strlen( $word ) > $limit ) && $out == null ) { return substr( $word, 0, $limit )."..."; } if (( strlen( $out ) + strlen( $word ) ) > $limit) { return $out . "..."; } $out.=" " . $word; } return $out; } echo limit_text("hello world lorem ipsum",10);

« previous php.notes (#216653) next »