note 36249 added to function.substr
| From: | sap_urg at gmx dot de | Date: | Thu, 02 Oct 2003 09:40:12 +0000 |
| Subject: | note 36249 added to function.substr | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-57601@lists.php.net to get a copy of this message | ||
I often had the problem to need a substring
without knowing the exact length,
but the sign or the position at which the string should end.
JavaScript supports this feature, but php doesn't, as far as I know.
Now, this function here does it:
function substring($str,$start,$stop){
if(is_string($stop))
$end=strlen($str)-(strlen($str)-strpos($str,$stop));
else
$end=strlen($str)-(strlen($str)-$stop);
return substr($str,$start,$end);
}
----
Manual Page -- http://www.php.net/manual/en/function.substr.php
Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+36249
Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+36249&report=yes
Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+36249&report=yes