Re: Use of substr()

From: Date: Fri, 03 Nov 2006 06:53:31 +0000
Subject: Re: Use of substr()
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-244135@lists.php.net to get a copy of this message
function format_text($a, $b) // $a is text to format, from textarea, $b is line length
                     { $line = array();
                        $limit = (strlen($a)/$b);
                       for($i = 0; $i < $limit; $i++)
                          {
                             $start = $i*$b;
                             $stop = (($i*$b) + $b) - 1;
                             print "start : $start     stop : $stop<br>";
                             array_push($line, substr($a, $start,
$stop)); // separate into lines not greater than $b length
                          }
                     return $line;
                      }
You made a minor mistake:) substr takes length as its third parameter, not stop. Here is the prototype of substr(): string *substr* ( string string, int start [, int length] ),

« previous php.general (#244135) next »