Home > other >  how to add variable link in html
how to add variable link in html

Time:02-10

i have a remote php file located on a server

https://webserver.com/file.php

and i have several images in html file on another server that are linked through

<div >
    <a href = "file.php?type=1"><img src="https://anysite.com/image.jpeg" alt="image" border="0"></a></br>
    logo
</div>

i want to replace the main link with a variable and add it to my images.

should appear link the following:

<div >
    <a href = "$variable?type=1"><img src="https://anysite.com/image.jpeg" alt="image" border="0"></a></br>
    logo
</div>

and the final link of the image will be:

https://webserver.com/file.php?type=1

Anyone can help please?

the html code is as follows:

<html> 
    <head> </head>
    <?php 
    var $variable = "https://webserver.com/file.php";
    ?>
    <body>
    <div >
    <a href = "$variable?type=1"><img src="https://anysite.com/image.jpeg" alt="image" border="0"></a>
    logo
</div>
<div >
    <a href = "$variable?type=2"><img src="https://anysite.com/image2.jpeg" alt="image2" border="0"></a>
    logo
</div>
</body>
</html>

CodePudding user response:

It's PHP, not Javascript question. You try something like this?

<div >
    <a href = "<?php echo $variable; ?>?type=1"><img src="https://anysite.com/image.jpeg" alt="image" border="0"></a></br>
    logo
</div>

EDIT:

complete example:

<?php 
    $variable = "https://webserver.com/file.php";
?>
<html> 
    <head> </head>
    <body>
    <div >
    <a href="<?php echo $variable; ?>?type=1"><img src="https://anysite.com/image.jpeg" alt="image" border="0"></a>
    logo
</div>
<div >
    <a href="<?php echo $variable; ?>?type=2"><img src="https://anysite.com/image2.jpeg" alt="image2" border="0"></a>
    logo
</div>
</body>
</html>
  •  Tags:  
  • Related