Page 1 of 1

Echo concatenation problem

Posted: Sun Sep 12, 2010 4:52 pm
by dave1dave
Hello -

This echo line
echo "<img src=http://www.aslinside.com/images/\" ".$info_box_sorted[3][0]."\">";

puts the following broken image link on my page
http://www.aslinside.com/images/%22

$info_box_sorted is an array with a value of 5_little_monkeys.jpg

Can you tell me how to fix the code that concatenates the array value to the image URL?

Thank you,


Dave

Re: Echo concatenation problem

Posted: Sun Sep 12, 2010 4:59 pm
by buckit

Code: Select all

echo "<img src=http://www.aslinside.com/images/".$info_box_sorted[3][0].">";
" starts a quoted section of your string... PHP will output to your browser EXACTLY what is between both quotes.

example:

Code: Select all

echo "hello";
will display, [text]hello[/text], in your browser. if you do:

Code: Select all

echo "\"hello\"";
that will output [text]"hello"[/text]. the \ escaped the second quote so it knows that you arent closing your quoted content. does that make sense?

so you had the following:

Code: Select all

 echo "<img src=http://www.aslinside.com/images/\" ".$info_box_sorted[3][0]."\">";
this is what you want to do
1) start your echo
echo
2) open a quote to start inserting the HTML you want PHP to send to your browser
"
2) type your html
<img src=http://www.aslinside.com/images/
3) close your quote so you can insert a PHP value in your echo
"
4) add a period to append your echo with more PHP
.
5) type in your variable you want displayed at that point in your echo string
$info_box_sorted[3][0]
5) add another period to append more to the string
.
6) open another quote to add more quoted HTML/TEXT
"
7) finish out your HTML (notice I put a forward slash as proper html image tags are the following: <img src='picture.jpg' />
/>
8) close the quote as we are done with quoted HTML
"
9) end your echo statement
;

Re: Echo concatenation problem

Posted: Sun Sep 12, 2010 5:57 pm
by dave1dave
Thank you.