• Blog

  • zatec.us
    • 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! (:


    Tweet


      • Rodrigo Marcel comentou em 25/07/2010 23:39:
      • Muito bom cara.. valew..

      • Rodrigo Marcel
    Envie seu comentário!
    Fechar

    Comentário

    Nome:

    E-mail: (Não será divulgado)

    Site ou blog: (Opcional)

    Comentário: (Máximo de 255 caracteres)

    Enviar


    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
  • zatec.us

  • © MMIX-MMXII Guilherme Augusto Madaleno
    Termos e Privacidade • Suporte • Contato

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

Ok