Breaking News
Loading...
September 28, 2014

How to generate the alias using PHP code

7:13 PM
The dream would be that it automatically checks if the alias already exists, and if necessary adds a prefix (or suffix) to ensure each alias is always unique.

this old-fashioned code (shame on me) can make it work, until the api is 100% complete :
<?php
$title = 'Title of the document';
makeAlias($title);
function makeAlias($url){
        $url    = no_accent($url);
        $url    = ereg_replace("[^a-z A-Z0-9-]*","",$url);
        $url    = ereg_replace("-{2,}","-",$url);
        $url    = ereg_replace(' ','-',$url);
        $url    = trim(strtolower($url));
        $url    = ltrim($url,'-');
        $url    = rtrim($url,'-');
        return $url;
}
function no_accent($filename) {
        $str = strtr(utf8_decode($filename),utf8_decode("ÀÁÂÃÄÅÇÑñÇçÈÉÊËÌÍÎÏÒÓÔÕÖØÙÚÛÜÝàáâãäåçèéêëìíîïðòóôõöøùúûüýÿ' "),"AAAAAACNnCcEEEEIIIIOOOOOOUUUUYaaaaaaceeeeiiiiooooooouuuuyy--" );
        return $str;
    }
?>

0 comments:

Post a Comment

 
Toggle Footer