liandri Posted May 28, 2010 Share Posted May 28, 2010 Bonjour,Petite proposition qui rendra encore plus performant les url rewrite dans la fonction Tools::link_rewrite()je vous propose de remplacer static public function link_rewrite($str, $utf8_decode = false) { $purified = ''; $length = self::strlen($str); if ($utf8_decode) $str = utf8_decode($str); for ($i = 0; $i < $length; $i++) { $char = self::substr($str, $i, 1); if (self::strlen(htmlentities($char)) > 1) { $entity = htmlentities($char, ENT_COMPAT, 'UTF-8'); $purified .= $entity{1}; } elseif (preg_match('|[[:alpha:]]{1}|u', $char)) $purified .= $char; elseif (preg_match('<[[:digit:]]|-{1}>', $char)) $purified .= $char; elseif ($char == ' ') $purified .= '-'; } return trim(self::strtolower($purified)); } par static public function link_rewrite($str, $utf8_decode = false) { $purified = ''; $length = self::strlen($str); if ($utf8_decode) $str = utf8_decode($str); for ($i = 0; $i < $length; $i++) { $char = self::substr($str, $i, 1); if (self::strlen(htmlentities($char)) > 1) { $entity = htmlentities($char, ENT_COMPAT, 'UTF-8'); $purified .= $entity{1}; } elseif (preg_match('|[[:alpha:]]{1}|u', $char)) $purified .= $char; elseif (preg_match('<[[:digit:]]|-{1}>', $char)) $purified .= $char; elseif ($char == ' ') $purified .= '-'; } $purified=preg_replace('/--+/', '-', $purified); return trim(self::strtolower($purified)); } soit l'ajout de la ligne $purified=preg_replace('/--+/', '-', $purified); qui va assurer de ne pas retrouver plusieurs fois le tiret dans l'url rewrite. C'est une simple optimisation sans prétention, mais qui rend le rewrite plus fini !A+ Link to comment Share on other sites More sharing options...
Yoya Posted May 28, 2010 Share Posted May 28, 2010 Merci à toi pour cette contribution A bientot,Pierre. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now