note 84775 modified in function.substr by thiago

From: Date: Tue, 29 Jul 2008 18:20:00 +0000
Subject: note 84775 modified in function.substr by thiago
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-142905@lists.php.net to get a copy of this message
I wrote this simple function <?php $input = "hello world" echo(limitchrmid($imput,10)) // hel ... rld //limit chars middle function limitchrmid($value,$lenght){ if (strlen($value) >= $lenght ){ $lenght_max = ($lenght/2)-3; $start = strlen($value)- $lenght_max; $limited = substr($value,0,$lenght_max); $limited.= " ... "; $limited.= substr($value,$start,$lenght_max); } else{ $limited = $value; } return $limited; } ?> --was-- I wrote this simple function $input = "hello world" echo(limitchrmid($imput,10)) // hel ... rld //limit chars middle function limitchrmid($value,$lenght){ if (strlen($value) >= $lenght ){ $lenght_max = ($lenght/2)-3; $start = strlen($value)- $lenght_max; $limited = substr($value,0,$lenght_max); $limited.= " ... "; $limited.= substr($value,$start,$lenght_max); } else{ $limited = $value; } return $limited; } http://php.net/manual/en/function.substr.php

« previous php.notes (#142905) next »