How do I link an image in PHP?

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'/>";
}

I would like to link an image in every echo .

    
asked by anonymous 27.08.2018 / 01:47

2 answers

3

To create a hyperlink we use the command formed by the pair of TAGS <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 on the word or phrase to display their destination.

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

Figure Hyperlink is a picture that has been assigned to a destination URL. In this case, the site visitor can click anywhere on the picture to display their destination.

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

In your application it 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>";
}
    
27.08.2018 / 02:03
3

In PHP there is no way because the language does not work with this, but HTML is wrong and 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 quite different from what is described.

The tag <a href> is the one that determines that there will be a link there. It exists by itself, what it will have inside may be various HTML elements, it may be a text or it may be an image. HTML tags are tags within each 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 it is only necessary to reproduce this code with the image name that is displayed and the 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>";
}

Documentation:

27.08.2018 / 01:59