Results 1 to 3 of 3

Thread: AAARRGGHHHH!!!!! Why is this so difficult????

  1. #1

    Thread Starter
    PowerPoster cafeenman's Avatar
    Join Date
    Mar 2002
    Location
    Florida
    Posts
    2,819

    AAARRGGHHHH!!!!! Why is this so difficult????

    Everyone told me PHP is easy. Now it won't accept a string with an apostrophe in it. What do I do about that?

    UserName = Bob
    Email = [email protected]
    Comments = These are Bob's comments

    It won't accept that. Why not? What do I do about it????

  2. #2
    PowerPoster
    Join Date
    Jul 1999
    Posts
    5,923
    ' is a string character as in most languages, therefore you have to "escape" it with the escape char \

    $string = 'these are bob\'s comments';

    You can get PHP to do it automatically turning the magic_quotes_gpc (for POST GET COOKIE data) and magic_quotes_runtime (for mysql data) directives on in your php.ini, or to do it in the script use the addslahes() function. Conversely, you can use stripslashes() function to remove them again if you want to display the output on the screen.
    Last edited by chrisjk; May 11th, 2002 at 10:09 AM.

  3. #3
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    When you have this:

    $x = 'these are bob's comments';

    the string ends at the next appostrophe, after bob. So with "s comments" it's searching for functions and stuff like that.

    If you know VB, it'd be like doing this:

    strString = "What's up," billy?

    You know that "billy?" would cause a syntax error.

    In order to fix this, you'd either have to escape it, like Chris showed, or if you know there's not going to be double quotes in the string, do this:

    "these are bob's comments" or
    'these are bob\'s comments"

    I hope you're starting to understand all this. PHP is a really awesome language once you get a handle on it. Best of luck.
    My evil laugh has a squeak in it.

    kristopherwilson.com

Posting Permissions

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



Click Here to Expand Forum to Full Width