How do I link an image in PHP?

Asked

Viewed 1,784 times

0

if($formaCombate == "patk")
{
    if($patk1 > $patk2)
    {
        echo "Jogador 1 Ganhou!";
    }
    elseif ($patk1 < $patk2)
    {
         echo "Vitória do jogador 2";
    }
    else
    {       
        echo "<img href='link'><img src='empat1.png'/>";
}

Would like to link an image in each echo.

  • if($formaCombate == "patk") { if($patk1 > $patk2) { echo "Player 1 Won!" ; } elseif ($patk1 < $patk2) { echo "Player 2 win"; } Else ː echo "<img href='link'><img src='empat1.png'/>"; }

  • This is all wrong <img href='link'> ... it’s right something like this: <a href='link'><img src='imagem.jpg'/></a>

  • Got it, I’ll try, thanks

  • Error on last line syntax :(

  • Mark the answer that solved your problem as accepted see https://i.stack.Imgur.com/evLUR.png and because https://pt.meta.stackoverflow.com/questions/1078/como-e-por-que-aceitar-uma-resposta/1079#1079

  • I still don’t really understand what you want... I think you could try to better explain the purpose or accept one of the answers below..

  • @Nathaliascatena Did any of the answers solve your question? Do you think you can accept one of them? Check out [tour] how to do this, if you haven’t already. You would help the community by identifying what was the best solution for you. You can accept only one of them. But you can vote on any question or answer you find useful on the entire site (when you have enough score).

Show 2 more comments

2 answers

3

In PHP there is no way because the language does not work with this, but in HTML there is way and is wrong in your code. PHP is just an agent that is generating HTML for you, so the question has nothing to do with this language, unless it is something quite different from what is described.

To tag <a href> is the one that determines that there will be a link there. It exists by itself, what you have inside can be several elements of HTML, can be a text or can be an image. HTML are tags one inside the other.

<a href = 'seu URL aqui'><img src = 'empat1.png'/></a>

If you want more readable:

<a href = 'seu URL aqui'>
    <img src = 'empat1.png'/>
</a>

In the case of others just play this code with the name of the image you want to be displayed and the due link:

if ($formaCombate == "patk") {
    if($patk1 > $patk2) echo "<a href = 'jogador1ganhou.html'><img src = 'venceu1.png'/></a>";
    elseif ($patk1 < $patk2) echo "<a href = 'jogador2ganhou.html'><img src = 'venceu2.png'/></a>";
    else echo "<a href = 'empatou.html'><img src = 'empat1.png'/></a>";
}

I put in the Github for future reference.

Documentations:

2

To create a hyperlink we use the command formed by the TAGS pair <a> </a> with the following syntax:

<a href="destino">texto ou figura ou elemento</a>

Text hyperlink is a word or phrase that has been assigned to a destination URL. In this case the site visitor can click anywhere in the word or phrase to display their destination.

example: <a href="destino">Texto</a>

Figure hyperlink is a figure that has been assigned to a destination URL. In this case, the site visitor can click on any part of the figure to display his destination.

example: <a href="destino"><img src="URL de origem da figura"></a>

In your application would look like this

if($formaCombate == "patk")
{
    if($patk1 > $patk2)
    {
        echo "<a href='link1'>Jogador 1 Ganhou!</a>";
    }
    elseif ($patk1 < $patk2)
    {
         echo "<a href='link2'>Vitória do jogador 2</a>";
    }
    else
    {       
        echo "<a href='link3'><img src='empat1.png'/></a>";
}

Browser other questions tagged

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