note 50162 deleted from function.substr by peehaa

From: Date: Mon, 28 Nov 2016 19:51:20 +0000
Subject: note 50162 deleted from function.substr by peehaa
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-207721@lists.php.net to get a copy of this message
Note Submitter: andrewmclagan at gmail dot com ---- 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; } ?>

« previous php.notes (#207721) next »