forked from NewEraCracker/php-work
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimproved_explode.php
More file actions
52 lines (44 loc) · 1.05 KB
/
Copy pathimproved_explode.php
File metadata and controls
52 lines (44 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
/*
Author: NewEraCracker
License: Public Domain
*/
function improved_explode($delimiter,$string,$escape=null)
{
$exploded = explode($delimiter,$string);
if($escape !== null)
{
// Fix exploded array to comply with escape char
foreach($exploded as $key => $value)
{
if ($value != '' && isset($exploded[$key]) )
{
if( stripos( $value.$delimiter, $escape.$delimiter) !== false )
{
// Merge $key and $key+1
$exploded[$key] = $exploded[$key] . $delimiter . ( isset($exploded[$key+1]) ? $exploded[$key+1] : '' );
// Fix $key
$exploded[$key] = str_replace( $escape.$delimiter , $delimiter , $exploded[$key]);
// Unset $key+1
if( isset($exploded[$key+1]) ) unset($exploded[$key+1]);
}
}
}
unset($key, $value);
// Fix array keys
$i = 0;
$new = array();
foreach($exploded as $key => $value)
{
$new[$i]=$exploded[$key];
$i++;
}
unset($key, $value);
$exploded = $new;
}
return $exploded;
}
// Example usage
$mystring = "test=2\\=2";
var_dump( improved_explode('=',$mystring,'\\') );
?>