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 3 of 3
  1. #1
    New to the CF scene
    Join Date
    May 2005
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Lightbulb Javascript Strings (please help!)

    Hi, I'm trying to pass a string into a function, but can't get around the way that the string has to be passed within quotes. For example, I have:

    somefunction("Paul said, "This isn't a great example, but it works."");

    Obviously the string will terminate early at the first ", and if I change the surrounding quotes to ', the string will also terminate early. Now, I'm pretty dumb but I do realize that I could just use an escape character to get around this problem, but the entire string
    Paul said, "This isn't a great example, but it works."
    Is brought in from a database (which is put in by a user who would know nothing about programming). Is there any way to get around this??? I know in PHP they have some kind of special way to notate a string without quotes (like <<< DOC string goes here >>>) or something like that. I tried to write a function that will replace the user-input ' and " with \' and \", but I can't even pass *that* function the string because of the same problem.
    Any help?

  • #2
    Senior Coder
    Join Date
    Feb 2004
    Location
    Edinburgh
    Posts
    1,352
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Code:
    somefunction('Paul said, "This isn't a great example, but it works."');
    *keep it simple (TM)

  • #3
    Regular Coder
    Join Date
    Jul 2002
    Location
    Canada, eh?
    Posts
    133
    Thanks
    2
    Thanked 3 Times in 3 Posts
    http://www.php.net/manual/en/function.addslashes.php

    whatever("<? echo addslashes($dbdata); ?>");



    This was never a JS problem. :-p


  •  

    Posting Permissions

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