toolman Posted January 21, 2010 Share Posted January 21, 2010 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 More sharing options...
gwolgamott Posted January 21, 2010 Share Posted January 21, 2010 $head_img = "img1.jpg"; echo "<img src='".$head_img."' />"; try that Link to comment https://forums.phpfreaks.com/topic/189350-help-with-echoing-image/#findComment-999528 Share on other sites More sharing options...
toolman Posted January 21, 2010 Author Share Posted January 21, 2010 Thanks, but that didn't work. I actually need the image to be in the $head = line $head = isset($_GET['text']) ? $_GET['text'] : "<img src="'$head_img'" />"; Link to comment https://forums.phpfreaks.com/topic/189350-help-with-echoing-image/#findComment-999543 Share on other sites More sharing options...
gwolgamott Posted January 21, 2010 Share Posted January 21, 2010 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; Link to comment https://forums.phpfreaks.com/topic/189350-help-with-echoing-image/#findComment-999560 Share on other sites More sharing options...
mattal999 Posted January 21, 2010 Share Posted January 21, 2010 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. Link to comment https://forums.phpfreaks.com/topic/189350-help-with-echoing-image/#findComment-999561 Share on other sites More sharing options...
gwolgamott Posted January 21, 2010 Share Posted January 21, 2010 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 Link to comment https://forums.phpfreaks.com/topic/189350-help-with-echoing-image/#findComment-999574 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.