Forum Moderators: coopster

Message Too Old, No Replies

URL concatenation

         

CNibbana

3:39 am on Oct 25, 2004 (gmt 0)

10+ Year Member



I have the following link which I believe should work:

print "<img src=\"http://domain.com/images/" . $icon . ".gif\" />";

however the resulting url is "http://domain.com/images/26%20%20%20%20.gif"

If I remove .gif from the end it prints the proper variable name. Am I using concatenation incorrectly? What am I doing wrong?

mincklerstraat

8:24 am on Oct 25, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



That concatenation looks ok to me. $icon probably isn't made up of just letters, numbers, -, and _? If so, this url might be fine as it is. It looks like the url is just being 'url encoded'.

Using single quotes around strings might help alleviate some confusion. Try:

echo '<img src="http://domain.com/images/' . $icon . '.gif" />';
- it helps you see what's a single quote, and what's a double quote, and 'echo' might be slightly more straightforward (less special funcitonality) than 'print'.

tomda

8:58 am on Oct 25, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



As said Mincklerstraat,

try this

echo '<img src="http://domain.com/images/'.$icon.'.gif" />';

or this

echo "<img src='http://domain.com/images/".$icon.".gif' />";

CNibbana

1:01 pm on Oct 25, 2004 (gmt 0)

10+ Year Member



I'm not sure what is or was causing the problem, however in the resulting url "http://domain.com/images/26%20%20%20%20.gif" the correct parts were included - '26' and '.gif'. For some reason the variable was being appended with '%20%20%20%20' no matter what format I used.

My solution ended up being printf("<img src=\"http://domain.com/images/%s.gif\"/>",htmlspecialchars(trim($icon))); to strip the %20.

Thanks for your help.