note 74146 added to function.wordwrap

From: Date: Tue, 27 Mar 2007 14:36:15 +0000
Subject: note 74146 added to function.wordwrap
Groups: php.notes 
Request: Send a blank email to php-notes+get-124850@lists.php.net to get a copy of this message
Improved version of egyptechno[at]gmail.com's wordCut. In this improved function, the length of $sMessage is taken into consideration while cutting the text, so the returned string is never longer than $iMaxLength. Besides that, whole words are cut as well. <?php /** * function wordCut($sText, $iMaxLength, $sMessage) * * + cuts an wordt after $iMaxLength characters * * @param string $sText the text to cut * @param integer $iMaxLength the text's maximum length * @param string $sMessage piece of text which is added to the cut text, e.g. '...read more' * * @returns string **/ function wordCut($sText, $iMaxLength, $sMessage) { if (strlen($sText) > $iMaxLength) { $sString = wordwrap($sText, ($iMaxLength-strlen($sMessage)), '[cut]', 1); $asExplodedString = explode('[cut]', $sString); echo $sCutText = $asExplodedString[0]; $sReturn = $sCutText.$sMessage; } else { $sReturn = $sText; } return $sReturn; } ?> ---- Server IP: 194.109.193.76 Probable Submitter: 137.224.233.96 ---- Manual Page -- http://www.php.net/manual/en/function.wordwrap.php Edit -- https://master.php.net/note/edit/74146 Del: integrated -- https://master.php.net/note/delete/74146/integrated Del: useless -- https://master.php.net/note/delete/74146/useless Del: bad code -- https://master.php.net/note/delete/74146/bad+code Del: spam -- https://master.php.net/note/delete/74146/spam Del: non-english -- https://master.php.net/note/delete/74146/non-english Del: in docs -- https://master.php.net/note/delete/74146/in+docs Del: other reasons-- https://master.php.net/note/delete/74146 Reject -- https://master.php.net/note/reject/74146 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#124850) next »