forked from Wavyzz/dolibarr
Debug v18
This commit is contained in:
@@ -2909,3 +2909,42 @@ function acceptLocalLinktoMedia()
|
||||
//return 1;
|
||||
return $acceptlocallinktomedia;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Remove first and last parenthesis but only if first is the opening and last the closing of the same group
|
||||
*
|
||||
* @param string $string String to sanitize
|
||||
* @return string String without global parenthesis
|
||||
*/
|
||||
function removeGlobalParenthesis($string)
|
||||
{
|
||||
$string = trim($string);
|
||||
|
||||
// If string does not start and end with parenthesis, we return $string as is.
|
||||
if (! preg_match('/^\(.*\)$/', $string)) {
|
||||
return $string;
|
||||
}
|
||||
|
||||
$nbofchars = dol_strlen($string);
|
||||
$i = 0; $g = 0;
|
||||
$countparenthesis = 0;
|
||||
while ($i < $nbofchars) {
|
||||
$char = dol_substr($string, $i, 1);
|
||||
if ($char == '(') {
|
||||
$countparenthesis++;
|
||||
} elseif ($char == ')') {
|
||||
$countparenthesis--;
|
||||
if ($countparenthesis <= 0) { // We reach the end of an independent group of parenthesis
|
||||
$g++;
|
||||
}
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
|
||||
if ($g <= 1) {
|
||||
return preg_replace('/^\(/', '', preg_replace('/\)$/', '', $string));
|
||||
}
|
||||
|
||||
return $string;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user