Skip to content

Instantly share code, notes, and snippets.

@ChMat
Created March 19, 2019 13:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ChMat/c62c2fbdfafbb30f5a1a2071ac9f7aa7 to your computer and use it in GitHub Desktop.
Save ChMat/c62c2fbdfafbb30f5a1a2071ac9f7aa7 to your computer and use it in GitHub Desktop.
Canonicalisation à la JF
<?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