Jump to content
Fórum Script Brasil
  • 0

Detectar automaticamente e criar link


guicampos1
 Share

Question

Bom dia,

Sei que o código de rastreio é constituído em: LLNNNNNNNNNLL (2 Letras, 9 Números e 2 Letras).

O que preciso é o seguinte, que no resultado da while, caso identifique algo nesse formato, ele faça o seguinte:

<a href="LLNNNNNNNNNLL">LLNNNNNNNNNLL</a>

Não sei se fui claro... Mas desde já agradeço!!!

Link to comment
Share on other sites

2 answers to this question

Recommended Posts

  • 0

Para isso podes usar expressões regulares, com a função preg_match. Algo assim:

<?php
 $arr = array("AB123456789CD", "CD987654321AB", "etcetal", "etc");
 $pattern = '/^\w{2}\d{9}\w{2}/';
 foreach ($arr as $item) 
 {
   if (preg_match($pattern, $item, $matches))
   {
     echo "<a href='{$matches[0]}'>{$matches[0]}</a><br />";
   }
 }
Edited by wootzor
Link to comment
Share on other sites

  • 0

Fiz da seguinte maneira:

$comentario_cru  = $ln["comment"];


 $expressao_codigo = "/[A-Z]{2}[0-9]{9}[A-Z]{2}/";
 $verifica   = preg_match($expressao_codigo, $comentario_cru, $codigo);
 $codigo     = "<a href='http://www.juicycompany.com.br/index.php?pagina=rastrear-pedido&codigo=".$codigo[0]."' target='_blank'>".$codigo[0]."</a>";
 $comentario = preg_replace($expressao_codigo, $codigo, $comentario_cru);
Edited by guicampos1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

  • Forum Statistics

    • Total Topics
      149.8k
    • Total Posts
      646.6k
×
×
  • Create New...