fork download
  1. <?php
  2. /**
  3.  * Generador de enlaces
  4.  *
  5.  * @author Alexis López Espinoza
  6.  * @param string $texto
  7.  * @return Texto con enlaces generados
  8.  */
  9.  
  10. function url($texto){
  11. $patron = '/(https?:\/\/)?([[a-z]+\.]?[a-z\d\-_]+\.[a-z\d]{2,6}(\.[a-z\d]{2,6})?([a-z\d\-_\/]+)?)/is';
  12. return preg_replace($patron, '<a href = "http://$2">$2</a>', $texto);
  13. }
  14.  
  15. echo url('Hola, por favor, visita www.google.com o http://w...content-available-to-author-only...o.com. Te esperamos.
  16.  
  17. También puedes ingresar a es.wikipedia.org o a HTTPS://W...content-available-to-author-only...A.COM/VIDEOS o incluso a http://n...content-available-to-author-only...x.com.');
Success #stdin #stdout 0.02s 24192KB
stdin
Standard input is empty
stdout
Hola, por favor, visita <a href = "http://www.google.com">www.google.com</a> o <a href = "http://w...content-available-to-author-only...o.com">www.yahoo.com</a>. Te esperamos.

También puedes ingresar a <a href = "http://e...content-available-to-author-only...a.org">es.wikipedia.org</a> o a <a href = "http://W...content-available-to-author-only...A.COM/VIDEOS">WWW.TERRA.COM/VIDEOS</a> o incluso a http://n...content-available-to-author-only...x.com.