note 85671 added to function.split
| From: | sue_hok at hotmail dot com | Date: | Thu, 11 Sep 2008 18:26:04 +0000 |
| Subject: | note 85671 added to function.split | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-144340@lists.php.net to get a copy of this message | ||
This function basically is to split the string from right with limit
<?php
function split_right($pattern,$input,$len=0)
{
if($len==0)
return split($pattern,$input);
$tempInput = split($pattern,$input);
$tempInput = array_reverse($tempInput);
$tempArray = array();
$ArrayIndex=0;
$indexCount=0;
foreach($tempInput as $values)
{
if($indexCount<$len)
{
$tempArray[$ArrayIndex]=$values;
if($indexCount<$len-1)
$ArrayIndex++;
}
else
{
$tempArray[$ArrayIndex]=$values.$pattern.$tempArray[$ArrayIndex];
}
$indexCount++;
}
return array_reverse($tempArray);
}
//For Example:
$string = "Hello World Split";
print_r(split(" ",$string,2));
print_r(split_right(" ",$string,2));
/*OutPut
Array
(
[0] => Hello
[1] => World Split
)
Array
(
[0] => Hello World
[1] => Split
)
*/
?>
----
Server IP: 124.217.231.13
Probable Submitter: 118.100.196.16
----
Manual Page -- http://www.php.net/manual/en/function.split.php
Edit -- https://master.php.net/note/edit/85671
Del: integrated -- https://master.php.net/note/delete/85671/integrated
Del: useless -- https://master.php.net/note/delete/85671/useless
Del: bad code -- https://master.php.net/note/delete/85671/bad+code
Del: spam -- https://master.php.net/note/delete/85671/spam
Del: non-english -- https://master.php.net/note/delete/85671/non-english
Del: in docs -- https://master.php.net/note/delete/85671/in+docs
Del: other reasons-- https://master.php.net/note/delete/85671
Reject -- https://master.php.net/note/reject/85671
Search -- https://master.php.net/manage/user-notes.php