canhnm

urlparser

Apr 7th, 2012
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.74 KB | None | 0 0
  1. <?php
  2. $str = 'Mời tham gia câu lạc bộ Những người ưa thích nghề quảng cáo
  3.  
  4. Các bạn click vào link này để tham gia nhé: http://cafecongso.com/room/discuss/Hoi-quang-cao-69.html';
  5.  
  6. define('PROXYURL', 'http://cafecongso.com/proxy?url=');
  7. function urlParser($str){
  8.     $str  = str_replace("\\r","\r",$str);
  9.     $str  = str_replace("\\n","\n<BR>",$str);
  10.     $str  = str_replace("\\n\\r","\n\r",$str);
  11.  
  12.     $in=array(
  13.       '`((?:https?|ftp)://\S+[[:alnum:]]/?)`si',
  14.       '`((?<!//)(www\.\S+[[:alnum:]]/?))`si'
  15.     );
  16.     $out=array(
  17.       '<a href="'.PROXYURL.'$1">$1</a> ',
  18.       '<a href="'.PROXYURL.'http://$proxyUrl$1">$1</a>'
  19.     );
  20.     return preg_replace($in,$out,$str);
  21. }
  22.  
  23. echo urlParser($str);
  24.  
  25. ?>
Advertisement
Add Comment
Please, Sign In to add comment