Created
August 2, 2014 11:33
-
-
Save Swop/02ece1ee82468a51f7e6 to your computer and use it in GitHub Desktop.
UrlEncodeType (credits: Benjamin Marquant)
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
<?php | |
/** | |
* @author Benjamin Marquant | |
* @website http://www.bxnxg.com | |
* @example http://website.com/My Fân Page !/ > http://website.com/my-fan-page/ and become a simple url rewriting | |
*/ | |
class UrlEncodeType { | |
private $url; | |
public function getUrl() | |
{ | |
return $this->url; | |
} | |
public function setUrl($url) | |
{ | |
/* automatic generation : accent replacment */ | |
$a = 'ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûýýþÿŔŕ&(!)_<>?/\:+="%'; | |
$b = 'aaaaaaaceeeeiiiidnoooooouuuuybsaaaaaaaceeeeiiiidnoooooouuuyybyRr,,,,,,,,,,,,,,,'; | |
$url = utf8_decode(strtolower(trim($url))); | |
$url = strtr($url, utf8_decode($a), $b); | |
$url = utf8_encode($url); | |
/* manual generation optimized for french language : you can add personnal replacement */ | |
$url = str_replace(",", "", $url); | |
$url = str_replace(".", "-", $url); | |
$url = str_replace("€", "euros", $url); | |
$url = str_replace("$", "dollars", $url); | |
$url = str_replace("t'", "", $url); | |
$url = str_replace("d'", "", $url); | |
$url = str_replace("l'", "", $url); | |
$url = str_replace("n'", "", $url); | |
$url = str_replace("'", "", $url); | |
$url = str_replace("\t", " ", $url); | |
$url = str_replace("\n", " ", $url); | |
$url = preg_replace("/[ ]+/", " ", $url); | |
$url = str_replace(" ", "-" , $url); | |
$url = str_replace("---", "-", $url); | |
$url = str_replace("--", "-", $url); | |
if (substr($url, -1, 1) == '-') { | |
$url = substr($url, 0, -1); | |
} | |
$this->url = $url; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment