forked from Wavyzz/dolibarr
NEW dolExplodeIntoArray can accept regex
This commit is contained in:
@@ -9805,13 +9805,21 @@ function printCommonFooter($zone = 'private')
|
||||
* For example: "A=1;B=2;C=2" is exploded into array('A'=>1,'B'=>2,'C'=>3)
|
||||
*
|
||||
* @param string $string String to explode
|
||||
* @param string $delimiter Delimiter between each couple of data
|
||||
* @param string $delimiter Delimiter between each couple of data. Example: ';' or '[\n;]+' or '(\n\r|\r|\n|;)'
|
||||
* @param string $kv Delimiter between key and value
|
||||
* @return array Array of data exploded
|
||||
*/
|
||||
function dolExplodeIntoArray($string, $delimiter = ';', $kv = '=')
|
||||
{
|
||||
if ($a = explode($delimiter, $string)) {
|
||||
if (preg_match('/^\[.*\]$/sm', $delimiter) || preg_match('/^\(.*\)$/sm', $delimiter)) {
|
||||
// This is a regex string
|
||||
$newdelimiter = $delimiter;
|
||||
} else {
|
||||
// This is a simple string
|
||||
$newdelimiter = preg_quote($delimiter, '/');
|
||||
}
|
||||
|
||||
if ($a = preg_split('/'.$newdelimiter.'/', $string)) {
|
||||
$ka = array();
|
||||
foreach ($a as $s) { // each part
|
||||
if ($s) {
|
||||
@@ -9824,6 +9832,7 @@ function dolExplodeIntoArray($string, $delimiter = ';', $kv = '=')
|
||||
}
|
||||
return $ka;
|
||||
}
|
||||
|
||||
return array();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user