Turquoise Rings - Debt Consolidation - Internet Advertising - Debt Consolidation - Debt Consolidation

PDA

View Full Version : formating url in php for javascript


Vijizzle
Jun 25th 2006, 3:20 pm
Howdy!

Im working on a php photo gallery.
I have my photos in a table and when you click on a photo an enlarged version of he photo is meant to appear in a new window.

This is the fairly standard code Im using to do that.

print '<td><img src="test.php?'.$photos[$i].'" onclick=window.open("'.$image_test.'","","width=641,height=434");></td>';

$image_test which looks like: http://localhost/site/photos/Fats Photos 3/001.jpg is where my problems lies.

Firstly the path in $photos[$i] looks like: photos\Fats Photos 3\001.jpg
Its exactly the same as $image_test except the back slashes are replaced.
To get it into a url format I used string replace and swapped all the \ for /.
Is there a better way of doing this?

Secondly some of the folder names have spaces in them e.g Fats Photos 3 if I pass this as $image_test the javascript will throw an undefined string error if i try urlencode($image_test) then I get an new window but no photo appears (this pages cannot be found....).

Im stumped.

Any help would be much appreciated.
Thanks

Vijizzle
Jun 25th 2006, 10:40 pm
I was using to encode the whole url eg.

urlencode("http://localhost/site/photos/Fats Photos 10/079.jpg")

when all I needed to so was encode the bit containing spaces eg.

$folder=urlencode("Fats Photos 10");

and then do something like this:

$complete_url="http://localhost/site/photos/".$folder."079.jpg";