Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    May 2011
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Quick Syntax Question

    Hi all,

    I have a problem that I've spent a bit of time trying to figure out, but to no avail.

    I'm trying to create a script which basically takes a selection from a drop down box and an image and re-names the image as the selection from the drop down box. I have everything done except for the last line of code which saves the image under the new name.

    Currently, I have:

    Code:
    $dest='images\$Order1.jpg';
    (Order1 is the name variable)

    This doesn't work, however. It simply saves the image as '$Order1.jpg'.

    I have tried messing around with the brackets, but I still havent found something that works.

    Thanks for any advice.
    Tim
    Last edited by Inigoesdr; 05-30-2011 at 04:43 AM.

  • #2
    New to the CF scene
    Join Date
    May 2011
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts
    EDIT: Found the answer. I just changed the direction of the slash. The working code is:

    Code:
    $dest="images/" . $Order1 .".jpg";

  • #3
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    The backslash in your original code is used to escape -- in this case escape the variable. In general you should always use forwardslashes in your paths as you figured out to prevent problems like these.

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    Quote Originally Posted by Inigoesdr View Post
    The backslash in your original code is used to escape -- in this case escape the variable. In general you should always use forwardslashes in your paths as you figured out to prevent problems like these.
    I agree, nowadays there will be no problem using the / in place of \ when accessing the filesystem.
    That said, if you really want to use them you would escape the escape. As mentioned, using 'images\$Order1.jpg' would actually create the literal string 'images$Order1.jpg'. The escape tells PHP to not parse that variable as a variable. For the backslash, you would instead use 'images\\$Order1.jpg', which will properly identify the \ instead of the escape.
    Most languages handle this better than PHP. Java won't compile for example when you try to give it a path like that. Its much smarter since it will actually evaluate the \x character to see if its an escape sequence before attempting to compile it. PHP on the other hand as a string based language doesn't really care if its in there as its not really a problem to have it.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •