예제 #1
0
 /**
  * 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
  *
  * @param string $str
  * @return string
  */
 public static function str2url($str)
 {
     static $allow_accented_chars = null;
     if ($allow_accented_chars === null) {
         $allow_accented_chars = JeproshopSettingModelSetting::getValue('allow_accented_chars_url');
     }
     if (is_array($str)) {
         print_r($str);
     }
     $str = trim($str);
     if (function_exists('mb_strtolower')) {
         $str = mb_strtolower($str, 'utf-8');
     }
     if (!$allow_accented_chars) {
         $str = JeproshopTools::replaceAccentedChars($str);
     }
     // Remove all non-white list 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 = JeproshopTools::strtolower($str);
     }
     return $str;
 }