note 50162 modified in function.substr by danbrown

From: Date: Fri, 28 Nov 2008 20:25:05 +0000
Subject: note 50162 modified in function.substr by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-147210@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 <?php 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; } ?> --was-- 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; } http://php.net/manual/en/function.substr.php

« previous php.notes (#147210) next »