Question:
PHP==> Using echo to insert a picture?
aryaxt
2006-06-14 11:34:41 UTC
Hi im trying to use echo and insert a picture like the code below:
echo "";
but i get this error :(
syntax error, unexpected T_STRING, expecting ',' or ';'
anybody knows y?
Seven answers:
Arbitrage
2006-06-14 11:38:39 UTC
You are getting messed up with the quotes. The easiest way to fix this is to take them out.



echo "";



Or you can escape the inner set of double quotes, but that's more work.
Tim P
2006-06-14 18:43:06 UTC
The previous answer is correct, however it's bad practice to leave things unquoted.



The error you are getting is due to your double quotes. The computer looks for an opening double quote (") then when it finds another one, it assumes that is the closing double quote. For example: ""; would be treated as two quoted parts, "". Obviously, this is not what you meant. To fix this you should do one of two things. First, you can use single quotes like this:



echo '';



Alternatively, you can escape the quotes (I prefer this method):



echo "";



The backslash before the quote tells the computer that you don't want to quote something, you want to put a quote character there.



I hope this helps!
anonymous
2006-06-14 21:06:33 UTC
I usually make a habit of always using single quotes (') when there is no variable to be interpreted inside the quote string. This does reduce the required processing a bit, and if you've got a lot of strings and/or a lot of visitors on the site, it can speed things up noticeably.



echo('


Then if you need to add a variable, do it by having separate strings and using concatenation with the . (period) operator, like this...



$image = 'lock.jpg';

echo('


Notice that I also have this strange habit of always using parenthesis to keep a consistent look-and-feel with other functions.
Beatmaster
2006-06-15 02:32:10 UTC
The problem you have it with your quotation marks. PHP thinks that you have ended the string after = " and therefore it expects either a , or a ;



You can simply do it like this:



echo '';

OR

echo "";

OR several other ways but my 1st example should work perfectly.
lbalan791
2006-06-14 18:39:50 UTC
Yes.. because you are using " inside your string. The syntax is echo string. Try to use echo "";
wilsoncruk
2006-06-14 19:09:29 UTC
You need to escape the quotes. Please, not the frontslash before the quotes. I recommend you to check this website for more info: http://www.tizag.com/phpT/echo.php





echo "";
Nixon
2006-06-20 16:34:16 UTC
Try echo "";



оr



?>





This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...