note 50162 added to function.substr
| From: | andrewmclagan at gmail dot com | Date: | Sun, 20 Feb 2005 09:58:12 +0000 |
| Subject: | note 50162 added to function.substr | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-85266@lists.php.net to get a copy of this message | ||
Hi there here is a little function i wrote to limit the number of lines in a string, i could not
find anything else like it out there
function lineLimiter ($string = "", $max_lines = 1) {
$string = ereg_replace("\n", "##", $string);
$totalLines = (substr_count($string, '##') + 1);
$string = strrev($string);
$stringLength = strlen($string);
while ($totalLines > $max_lines) {
$pos = 0;
$pos = strpos ( $string, "##") + 2;
//$pos = $pos - $stringLength;
$string = substr($string, $pos);
$totalLines--;
}
$string = strrev($string);
$string = ereg_replace("##", "\n", $string);
return $string;
}
----
Manual Page -- http://www.php.net/manual/en/function.substr.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+50162
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+50162&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+50162&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+50162&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+50162&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+50162&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+50162&report=yes
Search -- http://master.php.net/manage/user-notes.php