PHP coding. How to replace statement by variable?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
azadms
Forum Newbie
Posts: 5
Joined: Sat Oct 24, 2009 7:28 am

PHP coding. How to replace statement by variable?

Post by azadms »

I have the following code working fine with
echo '<img src = "adsphotos/myphoto.jpg" width="100" height="90" hspace="10" border="0" />';

Any one tell me how to replace "adsphotos/myphoto.jpg" by a variable like $filename and modify the coding?

It is not accepting :
$filename="adsphotos/myphoto.jpg";
echo '<img src = $filename width="100" height="90" hspace="10" border="0" />';
User avatar
yempee
Forum Newbie
Posts: 6
Joined: Sat Oct 24, 2009 5:56 am

Re: PHP coding. How to replace statement by variable?

Post by yempee »

<?php

$filename="images.jpeg";
echo '<img src = '.$filename.' width="100" height="90" hspace="10" border="0" />';

?>
Can u try the above one....
Mark Baker
Forum Regular
Posts: 710
Joined: Thu Oct 30, 2008 6:24 pm

Re: PHP coding. How to replace statement by variable?

Post by Mark Baker »

Slight fix yempee, quotes around the image src

Code: Select all

$filename="adsphotos/myphoto.jpg";
echo '<img src = "'.$filename.'" width="100" height="90" hspace="10" border="0" />';
 
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: PHP coding. How to replace statement by variable?

Post by jackpf »

8O
azadms
Forum Newbie
Posts: 5
Joined: Sat Oct 24, 2009 7:28 am

Re: PHP coding. How to replace statement by variable?

Post by azadms »

Really appreciating your fast reply. This reduces my headache. I tried to get information on net but I could not. Thank you very much once again.
veldthui
Forum Newbie
Posts: 10
Joined: Tue Oct 14, 2008 4:10 pm

Re: PHP coding. How to replace statement by variable?

Post by veldthui »

azadms wrote:Really appreciating your fast reply. This reduces my headache. I tried to get information on net but I could not. Thank you very much once again.
Gee and I thought this was the net :? . My bad.
Post Reply