Jump to content

help with echoing image


toolman

Recommended Posts

Hi,

 

I am trying to echo an image from a variable.

 

I have tried both of these, but cannot get it to work:

 

$head_img = "img1.jpg";
$head = isset($_GET['text']) ? $_GET['text'] : "<img src='$head_img' />"; 

 

and also

 

$head_img = array ("img1.jpg");
$head = isset($_GET['text']) ? $_GET['text'] : "<img src="'$head_img'" />"; 

 

Can someone help point out what I have wrong?

 

Thanks!

Link to comment
https://forums.phpfreaks.com/topic/189350-help-with-echoing-image/
Share on other sites

Give me more code so I can understand what you are trying to print and how? Or what exactly are you trying to do here? I just told you how to echo it with HTML.

 

But if you didn't try it this was what I was having you check, I assume u tried changing just this

'$head_img'

to this:

.$head_img.

Try it if you haven't already. Not sure if that will work, but it might.

 

Anyways for S&G's try this too:

$head_img = "img1.jpg";
$head_img = "<img src='".$head_img.". />";
$head = isset($_GET['text']) ? $_GET['text'] : $head_img; 

This WILL work, and is just a slight modification to your original code:

 

$head_img = "img1.jpg";
$head = isset($_GET['text']) ? $_GET['text'] : "<img src='".$head_img."' />";

If it doesn't work, then you need to post the error message you receive, or the result.

Yeah that's what I meant by this

'$head_img'

to this:

.$head_img.

Try it if you haven't already. Not sure if that will work, but it might.

... I didn't initially mean to change it to echo... but was an example... so try that as the code he has verbatim above if you haven't

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.