Domanda

This is my code:

<?php
      $lname = "templates/generator";
      $link = "<img src=\"{$lname}/data/num_{$row}.png\" alt=\"{$row}\"/>";
      echo $link;
?>

It does return this. Instead of an image, in the Firebug I can read the following:

<img src=" templates generator data num_1.png" alt="1">

So basically it is replacing the slashes with white spaces. Where is the problem in this code?

È stato utile?

Soluzione

A better idea would be to stop using messing with your quotes. Just sprintf() for outputting the HTML:

$link = sprintf('<img src="%s/data/num_%s.png" alt="%s"/>', $lname, $row, $row);

Also, while looking at your source, use your browser's View-Source feature, and not Firebug. It may be having it's own issues, as Ben said in the comments.

And to make sure you're not misreading the information, you can use a neat little header() trick:

header('Content-Type: text/plain');

PHP uses Content-Type text/html by default. Add this to the top of your script, and it'll display the HTML without any formatting and you can see what's really going on.

Altri suggerimenti

Try this:

Simply you should improve your line like this

$link = '<img src="{$lname}/data/num_{$row}.png" alt="{$row}" />';

Never use same commas in the same line, use different instead.

-

Thanks

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top