Forum Moderators: coopster

Message Too Old, No Replies

Echo PHP Variable inside PHP Echo

Echo PHP Variable inside PHP Echo

         

csatterwhite

2:56 am on Apr 23, 2012 (gmt 0)

10+ Year Member



In the code below, I need to echo the variable "path" in the HTML, next to last div, I'm doing it wrong obviously, can someone show me how to echo that variable inside an echo?

Thanks in advance.



<?php
if ($pagename=="index")

echo '



<div class="banner">

<div class="banner_title">
<strong>Your Health is the Keystone to Your Life</strong>
Call Us Today <span>(919) 444-5555</span>
</div>

<div class="ban_txt">

<div class="ban_title">Your Initial Consultation<br>is <span>FREE!</span></div>
<ul class="ban_list">
<li>Sed ullamcorper, enim vulputate dictum dapibus.</li>
<li>Libero lorem ullamcorper ipsum, nec ultricies.</li>
<li>Massa velit ut purus.</li>
</ul>
<div class="btn_contact"><a href="#">Contact Us Today</a></div>
</div>

<div class="ban_img"><img src="['$path']images/flash.png" alt=""></div>

</div><!--end of banner-->



';

else

echo "Have a nice day!";

?>

matrix_jan

3:45 am on Apr 23, 2012 (gmt 0)

10+ Year Member



try:

<img src="'.$path.'images/flash.png" alt="">

csatterwhite

4:04 am on Apr 23, 2012 (gmt 0)

10+ Year Member



Worked, thank you.

rocknbil

4:00 pm on Apr 23, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



can someone show me how to echo that variable inside an echo?


Welcome aboard csatterwhite, do you know why it worked? :-)

$var = 'hello world';

echo 'He said $var.'; // echoes 'He said $var.' - the literal

echo "He said $var."; // echoes "He said hello world." - scalar variables are interpolated with double quotes

echo 'He said ' . $var . '.'; // echoes "He said hello world." By concatenation, you can string together single quoted and double quoted strings with interpolated variables.