rabidmachine9
rabidmachine9

Reputation: 7975

echo an <img> tag

I'm going crazy trying to echo an <img> tag.

I want to add this simple string "/uploads/" before $photo->name.

Here is my echo: echo '<img src="'.$photo->name.'"/>';

Thanks for any help.

Upvotes: 1

Views: 48947

Answers (5)

Adiii
Adiii

Reputation: 59946

two ways to use echo tag

1st : one is double quotes which use for out put of strings

echo "your name is".$name //here name is variable

2nd : one is single quotes in which you can use all html tags here is the example

  <?php

     $name="Adil";
     echo $name;
     for($i=0;$i<44;$i++)
     {
       echo($i.'<br>')     ;
       if($i==10)
       {
         echo ' <table border=3> <tr><td><h1>its image </h1><img src="examp.png" alt="loading" /><td><td>hello</td><tr></table>';

       }
     }
     ?>

here i am using multiple tags in echo using

single quotes

if put double quotes then you will see following error Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in C:\xampp\htdocs\Untitled2d.php on line 21

here is the output enter image description here

Upvotes: 0

Jauzsika
Jauzsika

Reputation: 3251

Here you go: echo '<img src="/uploads/'.$photo->name.'"/>';

Or:

echo '<img src="' . '/uploads/' . $photo->name.'"/>';

Or:

echo '<img src="' . "/uploads/" . $photo->name.'"/>';

Upvotes: 2

JAL
JAL

Reputation: 21563

How about

 echo '<img src="/uploads/'.$photo->name.'"/>';

... unless I'm missing something?

Upvotes: 0

Paul Tomblin
Paul Tomblin

Reputation: 182782

echo '<img src="/uploads/'.$photo->name.'"/>';

Upvotes: 1

Alex B
Alex B

Reputation: 1448

Not sure if I completely understand, but try this:

echo '<img src="/uploads/'.$photo->name.'"/>';

Upvotes: 15

Related Questions