note 53605 modified in function.substr by danbrown

From: Date: Fri, 28 Nov 2008 20:22:59 +0000
Subject: note 53605 modified in function.substr by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-147206@lists.php.net to get a copy of this message
I have developed a function with a similar outcome to jay's Checks if the last character is or isnt a space. (does it the normal way if it is) It explodes the string into an array of seperate works, the effect is... it chops off anything after and including the last space. <?php function limit_string($string, $charlimit) { if(substr($string,$charlimit-1,1) != ' ') { $string = substr($string,'0',$charlimit); $array = explode(' ',$string); array_pop($array); $new_string = implode(' ',$array); return $new_string.'...'; } else { return substr($string,'0',$charlimit-1).'...'; } } ?> --was-- I have developed a function with a similar outcome to jay's Checks if the last character is or isnt a space. (does it the normal way if it is) It explodes the string into an array of seperate works, the effect is... it chops off anything after and including the last space. <? function limit_string($string, $charlimit) { if(substr($string,$charlimit-1,1) != ' ') { $string = substr($string,'0',$charlimit); $array = explode(' ',$string); array_pop($array); $new_string = implode(' ',$array); return $new_string.'...'; } else { return substr($string,'0',$charlimit-1).'...'; } } ?> http://php.net/manual/en/function.substr.php

« previous php.notes (#147206) next »