• Blog

  • Zatecus
    • PHP: Convertendo hyperlinks de string para HTML
    • Enviado em 25/07/2010 23:53
    • Uma ótima função como solução para geração de hyperlinks automaticamente utilizando o PHP!

      Função

      function makeHyperLinks($text)
      {
      	$text = html_entity_decode($text);
      	$text = " " . $text;
      	$text = eregi_replace('(((f|ht){1}tp://)[-a-zA-Z0-9@:%_\+.~#?&//=]+)', '<a href="\\1" target=_blank>\\1</a>', $text);
      	$text = eregi_replace('(((f|ht){1}tps://)[-a-zA-Z0-9@:%_\+.~#?&//=]+)', '<a href="\\1" target=_blank>\\1</a>', $text);
      	$text = eregi_replace('([[:space:]()[{}])(www.[-a-zA-Z0-9@:%_\+.~#?&//=]+)', '\\1<a href="http://\\2" target=_blank>\\2</a>', $text);
      	$text = eregi_replace('([_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,3})', '<a href="mailto:\\1" target=_blank>\\1</a>', $text);
      	return $text;
      }
      

      Utilização

      makeHyperLinks('Visite meu site http://www.zatecus.com');
      

      Thanks, Luca Matteis e um abraço a todos! (:


    Veja também:

    • PHP: Gerando hyperlinks do Twitter em string
    • PHP: Buscando informações do tempo em uma cidade
    • jQuery: Mini editor BBCode
    • Prêmio Peixe Grande 2010
    • PHP: Validar URL
  • Zatecus

  • Direitos reservados © MMIX-MMXIII
    Privacidade • Suporte • Contato

    • RSS
    • YouTube
    • LinkedIn
    • Twitter
    • Facebook
    • Topo
  • PayPal

Ok