Created
July 11, 2013 09:36
-
-
Save gpaton/5974034 to your computer and use it in GitHub Desktop.
Encode les URLs en supprimant les mots de liaison
This file contains hidden or 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
/** | |
* Encode name for URL | |
* | |
* @param string $p_sString | |
* @return string | |
*/ | |
public function encode ($p_sString) { | |
$_sReturn = utf8_decode($p_sString); | |
$_sReturn = strtolower($_sReturn); | |
$_sReturn = strtr($_sReturn, | |
utf8_decode('àáâãäåèéêëìíîïôöòóõñùúûü\'’‘'), | |
'aaaaaaeeeeiiiiooooonuuuu ' | |
); | |
$_sReturn = str_replace( | |
array( | |
chr(0xB2), | |
' ...', | |
' ?', | |
' !', | |
' :', | |
'/', | |
' de ', | |
' des ', | |
' du ', | |
' le ', | |
' les ', | |
' la ', | |
' d ', | |
' l ', | |
' par ', | |
' alors ', | |
' que ', | |
' qu ', | |
' un ', | |
' une ', | |
' et ', | |
' sur ', | |
' à ', | |
' son ', | |
'-' | |
), | |
array( | |
'2', | |
'', | |
'', | |
'', | |
'', | |
' ', | |
' ', | |
' ', | |
' ', | |
' ', | |
' ', | |
' ', | |
' ', | |
' ', | |
' ', | |
' ', | |
' ', | |
' ', | |
' ', | |
' ', | |
' ', | |
' ', | |
' ', | |
' ', | |
' ' | |
), | |
$_sReturn | |
); | |
$_sReturn = preg_replace('/^(le |la |les |des |un |une ){1}/','',$_sReturn); | |
$_sReturn = preg_replace('/[^a-z0-9 ]/','',$_sReturn); | |
$_sReturn = preg_replace('/[ ]{2,}/',' ',$_sReturn); | |
$_sReturn = preg_replace('/[ ]+$/','',$_sReturn); | |
$_sReturn = str_replace(' ','-',$_sReturn); | |
$_sReturn = utf8_encode($_sReturn); | |
return $_sReturn; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment