PHP urlize function

Posted by Maxime on Stack Overflow See other posts from Stack Overflow or by Maxime
Published on 2010-05-26T07:42:54Z Indexed on 2010/05/26 8:01 UTC
Read the original article Hit count: 331

Filed under:
|
|

Hello guys,

I'm using this function on my website to transform user input into acceptable URL:

function urlize($url) { 
$search = array('/[^a-z0-9]/', '/--+/', '/^-+/', '/-+$/' ); 
$replace = array( '-', '-', '', ''); 
return preg_replace($search, $replace, utf2ascii($url)); 
}     
function utf2ascii($string) { 
$iso88591  = "\\xE0\\xE1\\xE2\\xE3\\xE4\\xE5\\xE6\\xE7"; 
$iso88591 .= "\\xE8\\xE9\\xEA\\xEB\\xEC\\xED\\xEE\\xEF"; 
$iso88591 .= "\\xF0\\xF1\\xF2\\xF3\\xF4\\xF5\\xF6\\xF7"; 
$iso88591 .= "\\xF8\\xF9\\xFA\\xFB\\xFC\\xFD\\xFE\\xFF"; 
$ascii = "aaaaaaaceeeeiiiidnooooooouuuuyyy"; 
return strtr(mb_strtolower(utf8_decode($string), 'ISO-8859-1'),$iso88591,$ascii); 
}

I'm having a problem with it though, with numbers. For some reason when I try:

echo urlize("test 23342");

I get "test-eiioe". Why is that and how can I fix it?

Thank you very much!

© Stack Overflow or respective owner

Related posts about php

Related posts about web