NEW add option keepspace into dol_string_nospecialchar()

This commit is contained in:
Laurent Destailleur
2023-04-26 18:25:56 +02:00
parent f45c4dc867
commit 86456e299c
3 changed files with 26 additions and 4 deletions

View File

@@ -1447,13 +1447,17 @@ function dol_string_unaccent($str)
* @param string $newstr String to replace forbidden chars with
* @param array|string $badcharstoreplace Array of forbidden characters to replace. Use '' to keep default list.
* @param array|string $badcharstoremove Array of forbidden characters to remove. Use '' to keep default list.
* @param int $keepspaces 1=Do not treat space as a special char to replace or remove
* @return string Cleaned string
*
* @see dol_sanitizeFilename(), dol_string_unaccent(), dol_string_nounprintableascii()
*/
function dol_string_nospecial($str, $newstr = '_', $badcharstoreplace = '', $badcharstoremove = '')
function dol_string_nospecial($str, $newstr = '_', $badcharstoreplace = '', $badcharstoremove = '', $keepspaces = 0)
{
$forbidden_chars_to_replace = array(" ", "'", "/", "\\", ":", "*", "?", "\"", "<", ">", "|", "[", "]", ",", ";", "=", '°', '$', ';'); // more complete than dol_sanitizeFileName
$forbidden_chars_to_replace = array("'", "/", "\\", ":", "*", "?", "\"", "<", ">", "|", "[", "]", ",", ";", "=", '°', '$', ';'); // more complete than dol_sanitizeFileName
if (empty($keepspaces)) {
$forbidden_chars_to_replace[] = " ";
}
$forbidden_chars_to_remove = array();
//$forbidden_chars_to_remove=array("(",")");