note 119852 added to function.substr
| From: | m.m.j.kronenburg | Date: | Tue, 06 Sep 2016 22:46:53 +0000 |
| Subject: | note 119852 added to function.substr | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-206511@lists.php.net to get a copy of this message | ||
<?php
/**
* Returns and extracts the portion of string specified by the
* start and length parameters from the original string.
*
* This function is simulair to function substr() except that it
* removes the substring from the orignal string
* (passed by reference).
*
* @param string $string The input string.
* @param integer $start The start position (see substr() for
* explanation).
* @param integer $length The length (see substr()
* for explanation).
* @return mixed The substring or FALSE (see substr()
* for explanation).
**/
function substrex(&$string, $start, $length = PHP_INT_MAX)
{
if($start > strlen($string)) { return false; }
if(empty($length)) { return ''; }
if($start < 0) { $start = max(0, $start + strlen($string)); }
$end = ($length < 0) ?
strlen($string) + $length :
min(strlen($string), $start + $length);
if($end < $start) { return false; }
$length = $end - $start;
$substr = substr($string, $start, $length);
$string = substr($string, 0, $start).substr($string, $end);
return $substr;
}
?>
----
Server IP: 83.137.20.135
Probable Submitter: 141.105.0.254
----
Manual Page -- http://php.net/manual/en/function.substr.php
Edit -- https://master.php.net/note/edit/119852
Del: integrated -- https://master.php.net/note/delete/119852/integrated
Del: useless -- https://master.php.net/note/delete/119852/useless
Del: bad code -- https://master.php.net/note/delete/119852/bad+code
Del: spam -- https://master.php.net/note/delete/119852/spam
Del: non-english -- https://master.php.net/note/delete/119852/non-english
Del: in docs -- https://master.php.net/note/delete/119852/in+docs
Del: other reasons-- https://master.php.net/note/delete/119852
Reject -- https://master.php.net/note/reject/119852
Search -- https://master.php.net/manage/user-notes.php