/** * Return a friendly url made from the provided string * If the mbstring library is available, the output is the same as the js function of the same name * * Function by Prestashop * * @param string $str * @return string */ public static function generateUrl($str) { static $allow_accented_chars = null; $str = trim($str); if (function_exists('mb_strtolower')) { $str = mb_strtolower($str, 'utf-8'); } if (!$allow_accented_chars) { $str = Url::replaceAccentedChars($str); } // Remove all non-whitelist chars. if ($allow_accented_chars) { $str = preg_replace('/[^a-zA-Z0-9\\s\'\\:\\/\\[\\]-\\pL]/u', '', $str); } else { $str = preg_replace('/[^a-zA-Z0-9\\s\'\\:\\/\\[\\]-]/', '', $str); } $str = preg_replace('/[\\s\'\\:\\/\\[\\]-]+/', ' ', $str); $str = str_replace(array(' ', '/'), '-', $str); // If it was not possible to lowercase the string with mb_strtolower, we do it after the transformations. // This way we lose fewer special chars. if (!function_exists('mb_strtolower')) { $str = strtolower($str); } return $str; }