note 84907 added to function.substr
| From: | post | Date: | Tue, 05 Aug 2008 14:59:53 +0000 |
| Subject: | note 84907 added to function.substr | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-143165@lists.php.net to get a copy of this message | ||
Just a little function to cut a string by the wanted amount. Works in both directions.
<?php
function cutString($str, $amount = 1, $dir = "right")
{
if(($n = strlen($str)) > 0)
{
if($dir == "right")
{
$start = 0;
$end = $n-$amount;
} elseif( $dir == "left") {
$start = $amount;
$end = $n;
}
return substr($str, $start, $end);
} else return false;
}
?>
Enjoy ;)
----
Server IP: 217.160.72.57
Probable Submitter: 217.236.33.93
----
Manual Page -- http://www.php.net/manual/en/function.substr.php
Edit -- https://master.php.net/note/edit/84907
Del: integrated -- https://master.php.net/note/delete/84907/integrated
Del: useless -- https://master.php.net/note/delete/84907/useless
Del: bad code -- https://master.php.net/note/delete/84907/bad+code
Del: spam -- https://master.php.net/note/delete/84907/spam
Del: non-english -- https://master.php.net/note/delete/84907/non-english
Del: in docs -- https://master.php.net/note/delete/84907/in+docs
Del: other reasons-- https://master.php.net/note/delete/84907
Reject -- https://master.php.net/note/reject/84907
Search -- https://master.php.net/manage/user-notes.php