formating url in php for javascript

Discussion in 'PHP' started by Vijizzle, Jun 25, 2006.

  1. #1
    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 25, 2006 IP
  2. Vijizzle

    Vijizzle Peon

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    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";
     
    Vijizzle, Jun 25, 2006 IP