• Blog

  • Zatecus
    • PHP: Gerando hyperlinks do Twitter em string
    • Enviado em 26/07/2010 11:20
    • Esta simples função acrescenta hyperlinks em HTML nos status do Twitter, que são puxados via API.

      Função

      function addTwitterLink ($string) 
      {
      	$string = preg_replace("#(^|[\n ])([\w]+?://[\w]+[^ \"\n\r\t< ]*)#", "\\1<a href=\"\\2\" target=\"_blank\">\\2</a>", $string);
      	$string = preg_replace("#(^|[\n ])((www|ftp)\.[^ \"\t\n\r< ]*)#", "\\1<a href=\"http://\\2\" target=\"_blank\">\\2</a>", $string);
      	$string = preg_replace("/@(\w+)/", "<a href=\"http://www.twitter.com/\\1\" target=\"_blank\">@\\1</a>", $string);
      	$string = preg_replace("/#(\w+)/", "<a href=\"http://search.twitter.com/search?q=\\1\" target=\"_blank\">#\\1</a>", $string);
      	return $string;
      }
      

      Utilização

      addTwitterLink ('Bom dia do @zatec a todos os meus followers! #sayhello');
      

      Thanks to Snipe for this function (:


    Veja também:

    • PHP: Convertendo hyperlinks de string para HTML
    • PHP: Buscando informações do tempo em uma cidade
    • Prêmio Peixe Grande 2010
    • PHP: Validar URL
    • Momento retrô: Antigas gerações do zatecus.com
  • Zatecus

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

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

Ok