-2

I have an image URL, for example, http://URL/123.jpg. I can view the image in the browser, but it's not working when using the <img> tag in PHP. It's not working, and the idea is somehow not displayed.

echo "<img src=\"http://URL/123.jpg\" style=\"width:11%;height:auto;margin-left: 570px;margin-top: 170px;\">";

Any idea?

Viet Nguyen
  • 2,285
  • 2
  • 26
  • 43
  • Did you see the output in the browser console? Add it here so we can see. – Lucas Apr 21 '22 at 12:51
  • 1
    Clearly the issue is related to escaping, Try this echo ""; – Vishal Apr 21 '22 at 13:01
  • @Lucas, the output is blank similar to broken image – user2516703 Apr 21 '22 at 13:25
  • @Vishal based on your answer I'm receiving HTTP ERROR 500, please advise? – user2516703 Apr 21 '22 at 13:27
  • There is an php error, Add this line on top of the page error_reporting(-1); to know the exact error. – Vishal Apr 21 '22 at 13:30
  • @Vishal PHP Parse error: syntax error, unexpected '<' in. This is the error message. Also I have noticed that if I'm using url like this src="123.jpg" it's working, but my concern is I'm getting the jpg from another web site, so I have to use a url with http. Please advise? – user2516703 Apr 21 '22 at 13:35
  • @user2516703 Can you post whole line which you are using currently? – Vishal Apr 21 '22 at 13:41
  • 1
    If your site is HTTPS, and you're using an image from a HTTP site, it's not going to work. (This is a separate issue from your parse errors, though.) – ceejayoz Apr 21 '22 at 13:41
  • @Vishal here is my entire line echo ""; I think error in the \"http://test.com/123.jpg\" somewhere because if I called localhost jpg file for example like this \"123.jpg"\ it's working perfectly. – user2516703 Apr 21 '22 at 13:58
  • @ceejayoz. Perfect. The correct answer. Thank you very much – user2516703 Apr 21 '22 at 14:05

2 Answers2

-1

For php I use '' and for html the "" quotation marks. Don't know if it's gonna solve your issue tho. Maybe the height:auto; is the problem. I think you can even delete it, if you set the width the height should be auto by default.

echo '<img src="http://test.com/123.jpg" style="width:11%;margin-left: 570px;margin-top: 170px;" />';
Kip
  • 478
  • 4
  • 13
-2

Use Normal HTML syntax, include your php then save file as .php

<!DOCTYPE html>
<html>
<body>

<img src="https://external-content.duckduckgo.com/iu/?u=https%3A%2F%2Ftse1.mm.bing.net%2Fth%3Fid%3DOIP.GONAZbNLqDhBj8q4CpTnCQHaLH%26pid%3DApi&f=1" style="width:100px;height:auto;margin-left: 570px;margin-top: 170px;"/>

<!--your php file-->
<?php include 'footer.php';?>
</body>
</html>

Don't forget you have to save this file as PHP.

hhelsinki
  • 46
  • 4