note 60100 added to function.split
| From: | shimon at schoolportal dot co dot il | Date: | Mon, 26 Dec 2005 20:34:35 +0000 |
| Subject: | note 60100 added to function.split | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-100751@lists.php.net to get a copy of this message | ||
<?
// **
// * splitslash()
// *
// * this function enables to split with an escape char;
// *
// * @since 25/12/05 21:26:00
// * @author Shimon Doodkin
// *
// * @param $string
// * @param $string
// * @return Array()
// **
function splitslash($split,$str,$esc='\\\\')
{
$o=explode($split,$str);
$oc=count($o);
$a=array();
for($i=0;$i<$oc;$i++)
{
$o2=explode($esc.$esc,$o[$i]);
$o2c=count($o2);
if($o2[$o2c-1][strlen($o2[$o2c-1])-1]==$esc)
{
$o2[$o2c-1]=substr($o2[$o2c-1],0,-1);
if($i+1<$oc)
{
$o[$i+1]=join($esc.$esc,$o2).$split.$o[$i+1];
}
else
{
//echo "error";
$a[]=join($esc,$o2); //do like ok
}
}
else
{
$a[]=join($esc,$o2);
}
}
return $a;
}
// example:
$r=splitslash("NA","mooNAmooNAma\\\\ma\\NA");
print_r($r);
//output:
/*
Array
(
[0] => moo
[1] => moo
[2] => ma\\maNA
)
*/
?>
----
Manual Page -- http://www.php.net/manual/en/function.split.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+60100
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+60100&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+60100&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+60100&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+60100&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+60100&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+60100&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+60100&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+60100&report=yes
Search -- http://master.php.net/manage/user-notes.php