note 33764 added to ref.strings
| From: | MDonatas at centras dot lt | Date: | Mon, 07 Jul 2003 10:21:43 +0000 |
| Subject: | note 33764 added to ref.strings | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-51615@lists.php.net to get a copy of this message | ||
I had to "translate" some project from ASP to PHP and found that in ASP there are some
very useful string functions like:
string left ( string string, int length )
string right ( string string, int length )
string mid ( string string, int start [, int length] )
I think it's not hard to figure out what these functions do. If anyone finds it useful (I did),
here is the code:
function left ($str, $howManyCharsFromLeft)
{
return substr ($str, 0, $howManyCharsFromLeft);
}
function right ($str, $howManyCharsFromRight)
{
$strLen = strlen ($str);
return substr ($str, $strLen - $howManyCharsFromRight, $strLen);
}
function mid ($str, $start, $howManyCharsToRetrieve = 0)
{
$start--;
if ($howManyCharsToRetrieve === 0)
$howManyCharsToRetrieve = strlen ($str) - $start;
return substr ($str, $start, $howManyCharsToRetrieve);
}
----
Manual Page -- http://www.php.net/manual/en/ref.strings.php
Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+33764
Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+33764&report=yes
Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+33764&report=yes