Browse Source

Ajout d'une canonicalization plus stricte.

Bastien Sevajol 11 years ago
parent
commit
be363775cf
1 changed files with 23 additions and 0 deletions
  1. 23 0
      src/Muzich/CoreBundle/Util/StrictCanonicalizer.php

+ 23 - 0
src/Muzich/CoreBundle/Util/StrictCanonicalizer.php View File

@@ -46,4 +46,27 @@ class StrictCanonicalizer implements CanonicalizerInterface
46 46
     // On retire les accents occidentaux.
47 47
     return $this->remove_accent($string);
48 48
   }
49
+  
50
+  public function canonicalize_stricter($string)
51
+  {
52
+    $string = $this->canonicalize($string);
53
+    
54
+    // Remove accents from characters
55
+    $string = iconv('UTF-8', 'ASCII//TRANSLIT', $string);
56
+
57
+    // Everything lowercase
58
+    $string = strtolower($string);
59
+
60
+    // Replace all non-word characters by dashes
61
+    $string = preg_replace("/\W/", "-", $string);
62
+
63
+    // Replace double dashes by single dashes
64
+    $string = preg_replace("/-+/", '-', $string);
65
+
66
+    // Trim dashes from the beginning and end of string
67
+    $string = trim($string, '-');
68
+
69
+    return $string;
70
+  }
71
+  
49 72
 }