PHP bir workeable

Ben bu kodu kullanıyorum

$patterns = "!((http:/{2}[\w\.]{2,}[/\w\-\.\?\&\=\#]*)|(www\.[/\w\-\.\?\&\=\#]*)|([a-zA-Z0-9-\.]+(com|us|co.il)[^\s]*))!e";
 return preg_replace($patterns, "'<a class=\"highlight boughtAt\" href=\"\\1\" title=\"\\1\" target=\"_blank\">'.(strlen('\\1')>=$chr_limit ? substr('\\1',0,$chr_limit).'$add':'\\1').'</a>'", $url);

but my problem is that if I get the www. or just .com I get in the href= the prefix of the domain that i'm in. How can i avoid it? just get a working link?

Tx in advance, Roy

1 Cevap

Bir Geriye bakan iddiayı kullanmak gerekir - (?<=...) daha sonra her zaman bağlantı http:// ekleyin:

$patterns = "!(((?<=http:/{2})[\w\.]{2,}[/\w\-\.\?\&\=\#]*)|(www\.[/\w\-\.\?\&\=\#]*)|([a-zA-Z0-9-\.]+(com|us|co.il)[^\s]*))!e";
return preg_replace($patterns, "'<a class=\"highlight boughtAt\" href=\"http://\\1\" title=\"\\1\" target=\"_blank\">'.(strlen('\\1')>=$chr_limit ? substr('\\1',0,$chr_limit).'$add':'\\1').'</a>'", $url);