note 58117 added to function.substr

From: Date: Tue, 25 Oct 2005 00:32:10 +0000
Subject: note 58117 added to function.substr
Groups: php.notes 
Request: Send a blank email to php-notes+get-97535@lists.php.net to get a copy of this message
Hi, I tried this script with a headlines page, 20 news with 20 extracted text, but it come a messagge: Fatal error: Cannot redeclare truncate_string() (previously declared in c:\programmi\easyphp1-8\www\onlinetopcasino\phpnews\headlines.php:82) in c:\programmi\easyphp1-8\www\onlinetopcasino\phpnews\headlines.php on line 82 Please help me. <?php $string = "Truncates a string at a certain position without &raquo;cutting&laquo; words into senseless pieces."; $maxlength = 75; $extension = " ..."; function truncate_string ($string, $maxlength, $extension) { // Set the replacement for the "string break" in the wordwrap function $cutmarker = "**cut_here**"; // Checking if the given string is longer than $maxlength if (strlen($string) > $maxlength) { // Using wordwrap() to set the cutmarker // NOTE: wordwrap (PHP 4 >= 4.0.2, PHP 5) $string = wordwrap($string, $maxlength, $cutmarker); // Exploding the string at the cutmarker, set by wordwrap() $string = explode($cutmarker, $string); // Adding $extension to the first value of the array $string, returned by explode() $string = $string[0] . $extension; } // returning $string return $string; } // This Will output: // "Truncates a string at a certain position without &#65533;cutting&#65533; ..." echo truncate_string ($string, $maxlength, $extension); ?> p.s. include_once and require_once it isn't, for my situation, the solution. Thanks ---- Manual Page -- http://www.php.net/manual/en/function.substr.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+58117 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+58117&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+58117&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+58117&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+58117&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+58117&report=yes&reason=non-english Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+58117&report=yes&reason=already+in+docs Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+58117&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+58117&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#97535) next »