Echo concatenation problem

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
dave1dave
Forum Newbie
Posts: 2
Joined: Sun Sep 12, 2010 4:37 pm

Echo concatenation problem

Post 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
buckit
Forum Contributor
Posts: 169
Joined: Fri Jan 01, 2010 10:21 am

Re: Echo concatenation problem

Post 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
;
dave1dave
Forum Newbie
Posts: 2
Joined: Sun Sep 12, 2010 4:37 pm

Re: Echo concatenation problem

Post by dave1dave »

Thank you.
Post Reply