View Single Post
Old 08-14-2009, 02:31 PM   #1 (permalink)
oMIKEo
The Contributor
 
oMIKEo's Avatar
 
Join Date: Jan 2008
Location: Leeds
Posts: 52
Thanks: 7
oMIKEo is on a distinguished road
Default Special characters function

Hi, I have this function that takes a title with any random characters in it and generates a friendly url from it:

PHP Code:
function generateFriendlyURL($title)
{            
            
// Switch none standard letters 
            
$title1 strtr($title,"ŠŒŽšœžŸ¥µÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýÿ","SOZsozYYuAAAAAAACEEEEIIIIDNOOOOOOUUUUYsaaaaaaaceeeeiiiionoooooouuuuyy"); 
            
            
// Remove special chars
            
$allowed "/[^a-z0-9\\040\\.\\-\\_]/i";
            
$title1 preg_replace($allowed,"",$title1); 
            
            
// Replace spaced with _
            
$title1 preg_replace('/\s/''_'$title1); 
            
            
// Save
            
return $title1;

To test it I've then entered in this:

Code:
ŠŒŽšœžŸ¥µÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýÿ
but the resulting friendly url is:

Code:
AAAAAAAAYAuAAAAAAAAAAASAAOAAZAAAAAAAAAAAsAAoAAYAAAAAAYAAAAAAAAAAAAAAAAuAAAAAAAA
Any ideas where I am going wrong?

Thanks,
Michael
Send a message via MSN to oMIKEo
oMIKEo is offline  
Reply With Quote