note 81220 added to function.explode

From: Date: Tue, 19 Feb 2008 04:53:08 +0000
Subject: note 81220 added to function.explode
Groups: php.notes 
Request: Send a blank email to php-notes+get-136264@lists.php.net to get a copy of this message
Hey a small fix in my code <?php /** * Function abbreviate * return abbreviate name * This function is to abbreviate the name. If name is grater than specific length * then it abbreviate the string * * * Parameters: * limit - The maximum character count * string - The name string * * Returns: * string - abbreviated string */ function abbreviate($limit, $string, $position=0) { $char_limit=$limit; $string = trim($string); $str_chunk = explode(' ', $string); if(strlen($string) > $char_limit) { if(sizeof($str_chunk) == ($position+1)){ return $string = substr($string, 0, $char_limit); } else { $str_chunk[$position] = substr($str_chunk[$position], 0, 1).'.'; return abbreviate($char_limit,implode(' ',$str_chunk), ++$position); } } else { return $string; } } //Usage $name = 'Abhinav Varshney This Is My Name'; $char_limit=29; echo abbreviate($char_limit, $name); // Output:: // A. Varshney This Is My Name ?> ---- Server IP: 203.199.69.133 Probable Submitter: 202.164.58.81 ---- Manual Page -- http://www.php.net/manual/en/function.explode.php Edit -- https://master.php.net/note/edit/81220 Del: integrated -- https://master.php.net/note/delete/81220/integrated Del: useless -- https://master.php.net/note/delete/81220/useless Del: bad code -- https://master.php.net/note/delete/81220/bad+code Del: spam -- https://master.php.net/note/delete/81220/spam Del: non-english -- https://master.php.net/note/delete/81220/non-english Del: in docs -- https://master.php.net/note/delete/81220/in+docs Del: other reasons-- https://master.php.net/note/delete/81220 Reject -- https://master.php.net/note/reject/81220 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#136264) next »