Skip to content

Instantly share code, notes, and snippets.

@Swop
Created August 2, 2014 11:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Swop/02ece1ee82468a51f7e6 to your computer and use it in GitHub Desktop.
Save Swop/02ece1ee82468a51f7e6 to your computer and use it in GitHub Desktop.
UrlEncodeType (credits: Benjamin Marquant)
<?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