How to send variable with link in PHP

Asked

Viewed 152 times

1

so I’m having doubts on how to make this link in php:

<a href="DepoimentosPT-BR.php?id=<?php echo $_SESSION['idusuario']; ?>">Depoimentos</a></li>

as you can see this link is in html and then is called php to send the $ with and the ? id.

I want to know how I do this way in php same type:

echo "...";

1 answer

5

Considering $id = $_SESSION['idusuario'].

  1. Concatenating strings:

    echo '<a href="DepoimentosPT-BR.php?id='.$id.'">Depoimentos</a>';
    
  2. Interpolating strings:

    echo "<a href='DepoimentosPT-BR.php?id={$id}'>Depoimentos</a>";
    
  3. Formatting strings with sprintf:

    echo sprintf("<a href='DepoimentosPT-BR.php?id=%d'>Depoimentos</a>", $id);
    
  4. Translation of characters from string:

    echo strtr("<a href='DepoimentosPT-BR.php?id={id}'>Depoimentos</a>", '{id}', $id);
    
  • 1

    Thanks my brother, help me ;;)

  • +1 for sprintf

  • @Pedrolukas you should mark the answer as the correct one for your question.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.