1

before asking this question i have been looking at these 2 posts but i can't seem to find the answer:

Using PHP variables inside HTML tags?

how do use php variable in html?

I want to create a simple script that displays images with different links using values stored in variables but my script is not working.

<?php
    $array = array(
      "http://yahoo.com",  
      "http://bing.com",  
    );
    for ($val = 0; $val<2; $val++) {
      $b1 = "<a href='{$array[$val]}' target="_blank"><img src="./$val/1.jpg" alt="image here" title="Title"></a>";
      print $b1;
    }
?>

I apologize in advance, pretty sure it's a really dumb question but i really can't find a solution by myself...

Thanks!

1
  • need to escape the double quotes $b1 = "<a href='{$array[$val]}' target=\"_blank\"><img src=\"./$val/1.jpg\" alt=\"image here\" title=\"Title\"></a>"; Commented May 17, 2017 at 9:17

3 Answers 3

1

try this



     $array = array(
          "http://yahoo.com",  
          "http://bing.com",  
        );
        for ($val = 0; $val";
          print $b1;
        }


Sign up to request clarification or add additional context in comments.

Comments

0
try this

    <?php
$array = array(
          "http://yahoo.com",  
          "http://bing.com",  
        );
        for ($val = 0; $val<2; $val++) {
          $b1 = "<a href='{$array[$val]}' target='_blank'><img src='../$val/1.jpg' alt='image here' title='Title'></a>";
          print $b1;
        }
?>

Please replace double quote to sinlge qoute

Comments

0

Need to escape the double quotes target=\"_blank\"

 $b1 = "<a href='{$array[$val]}' target=\"_blank\"><img src=\"./$val/1.jpg\" alt=\"image here\" title=\"Title\"></a>"; 

OR

use single quotes inside the the double quotes like this

$b1 = "<a href='{$array[$val]}' target='_blank'><img src='./$val/1.jpg' alt='image here' title='Title'></a>";

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.