Created
March 19, 2019 13:04
-
-
Save ChMat/c62c2fbdfafbb30f5a1a2071ac9f7aa7 to your computer and use it in GitHub Desktop.
Canonicalisation à la JF
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Entité bidon, juste pour illustrer le principe | |
*/ | |
class Entity { | |
/** | |
* @var string | |
*/ | |
private $canonicalContent; | |
/************************************************/ | |
/* */ | |
/* Lifecycle Events */ | |
/* */ | |
/************************************************/ | |
/** | |
* Canonical name is used to perform search into this Entity | |
* @ORM\PreUpdate() | |
* @ORM\PrePersist() | |
*/ | |
public function fillCanonicalContent() | |
{ | |
$a = str_replace(' ', '', ($this->getContent())); | |
$a = self::regexAccents($a); | |
$out = mb_ereg_replace("[^A-Za-z0-9\+]", "", $a); | |
$this->canonicalContent = mb_strtolower($out, 'UTF-8'); | |
} | |
/** | |
* Nettoie une chaine de caractère composée d'accents | |
* | |
* @param $string | |
* @param string $encId | |
* | |
* @return string | |
*/ | |
public static function regexAccents($string, $encId = 'UTF-8') | |
{ | |
setlocale(LC_ALL, 'fr_BE.utf8'); | |
return iconv($encId, 'ASCII//TRANSLIT', $string); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment