Spyderman Posted January 4, 2010 Share Posted January 4, 2010 Hi all, I'm looking for a way to display an image, centered, using only php. The reason it can't use html is the image I am displaying is a variable $path, and the image will display when I call a function. The code I have now is <? $path="imgs/image.jpg"; displayImage(); function displayImage() { echo"<img id="img_center" src=$path>"; } ?> but when I am using the 'echo', I am unable to use the $path variable. Which is why I am trying to do it without using html. Thanks alot! Link to comment https://forums.phpfreaks.com/topic/187065-displaying-a-centered-image-without-html/ Share on other sites More sharing options...
RaythMistwalker Posted January 4, 2010 Share Posted January 4, 2010 <? $path="imgs/image.jpg"; displayImage(); function displayImage() { echo"<center><img id="img_center" src=".$path."></center>"; } ?> Should work Link to comment https://forums.phpfreaks.com/topic/187065-displaying-a-centered-image-without-html/#findComment-987827 Share on other sites More sharing options...
Spyderman Posted January 4, 2010 Author Share Posted January 4, 2010 Thanks for the response! Unfortunately that doesn't work =[. When I do this, the .$path. doesn't register as a variable, but the path location itself. echo'<center><img src=".$path."></center>'; Thank you so much for the help! Link to comment https://forums.phpfreaks.com/topic/187065-displaying-a-centered-image-without-html/#findComment-987871 Share on other sites More sharing options...
teamatomic Posted January 4, 2010 Share Posted January 4, 2010 if what you are trying to do is get the <img> tag to be used for php display at a later date try enclosing the echo stuff in single quotes. That way the var wont extrapolate but will display literally. HTH Teamatomic Link to comment https://forums.phpfreaks.com/topic/187065-displaying-a-centered-image-without-html/#findComment-987878 Share on other sites More sharing options...
calmchess Posted January 4, 2010 Share Posted January 4, 2010 echo"<center><img src=$path></center>"; everything is already a string no use breaking it up Link to comment https://forums.phpfreaks.com/topic/187065-displaying-a-centered-image-without-html/#findComment-987880 Share on other sites More sharing options...
Spyderman Posted January 4, 2010 Author Share Posted January 4, 2010 Thanks for the help everyone! This is what ended up working for me $path="imgs/image.jpg"; echo'<center><img src="'.$path.'"></center>'; Link to comment https://forums.phpfreaks.com/topic/187065-displaying-a-centered-image-without-html/#findComment-987884 Share on other sites More sharing options...
Tazerenix Posted January 4, 2010 Share Posted January 4, 2010 as far as i know echo "<img id=\"img_center\" src=\"$path\" />"; would also have worked Link to comment https://forums.phpfreaks.com/topic/187065-displaying-a-centered-image-without-html/#findComment-987894 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.