Re: Use of substr()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




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] ),

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux