mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2025-02-20 13:46:52 +01:00
Add slugify function for security purpose
This commit is contained in:
parent
db128814b5
commit
b6390f959c
|
|
@ -1874,6 +1874,33 @@ function dol_string_nounprintableascii($str, $removetabcrlf = 1)
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns text slugified (no special char, separator is "-".
|
||||
*
|
||||
* @param string $stringtoslugify String to slugify
|
||||
* @return string Slugified string
|
||||
*/
|
||||
function dolSlugify($stringtoslugify)
|
||||
{
|
||||
$slug = dol_string_unaccent($stringtoslugify);
|
||||
|
||||
// Convert special characters to their ASCII equivalents
|
||||
if (function_exists('iconv')) {
|
||||
$slug = iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', $slug);
|
||||
}
|
||||
|
||||
// Convert to lowercase
|
||||
$slug = strtolower($slug);
|
||||
|
||||
// Replace non-alphanumeric characters with hyphens
|
||||
$slug = preg_replace('/[^a-z0-9]+/', '-', $slug);
|
||||
|
||||
// Remove leading and trailing hyphens
|
||||
$slug = trim($slug, '-');
|
||||
|
||||
return $slug;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns text escaped for inclusion into javascript code
|
||||
*
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user