note 87438 modified in function.explode by danbrown

From: Date: Fri, 05 Dec 2008 05:29:59 +0000
Subject: note 87438 modified in function.explode by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-147665@lists.php.net to get a copy of this message
<?php // Remove words if more than max allowed character are insert or add a string in case less than min are displayed // Example: LimitText("The red dog ran out of thefence",15,20,"<br>"); function LimitText($Text,$Min,$Max,$MinAddChar) { if (strlen($Text) < $Min) { $Limit = $Min-strlen($Text); $Text .= $MinAddChar; } elseif (strlen($Text) >= $Max) { $words = explode(" ", $Text); $check=1; while (strlen($Text) >= $Max) { $c=count($words)-$check; $Text=substr($Text,0,(strlen($words[$c])+1)*(-1)); $check++; } } return $Text; } ?> --was-- // Remove words if more than max allowed character are insert or add a string in case less than min are displayed // Example: LimitText("The red dog ran out of thefence",15,20,"<br>"); function LimitText($Text,$Min,$Max,$MinAddChar) { if (strlen($Text) < $Min) { $Limit = $Min-strlen($Text); $Text .= $MinAddChar; } elseif (strlen($Text) >= $Max) { $words = explode(" ", $Text); $check=1; while (strlen($Text) >= $Max) { $c=count($words)-$check; $Text=substr($Text,0,(strlen($words[$c])+1)*(-1)); $check++; } } return $Text; } http://php.net/manual/en/function.explode.php

« previous php.notes (#147665) next »