SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict
    Join Date
    Sep 2008
    Posts
    235
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    addslashes- stripslashes problem

    i have a form for exam where the user can enter data in text field with any special character (quote ('), double quote ("), backslash (\))

    so i use addslashes in post then i echo the field using stripslashes and everything till this point is OK.

    my problem is that the answer may contains a slash in the text field e.g: jo\hn
    but when i tried to echo it using stripslashes it echos "john" which is wrong.

    i used addslashes and addcslashes to try fix this error but it still exists

    i want to add slashes to all special character except the backslashes "'\" .. so the answer to be as it is "jo\hn"

    any idea

  2. #2
    SitePoint Wizard bronze trophy chris.upjohn's Avatar
    Join Date
    Apr 2010
    Location
    Melbourne, AU
    Posts
    2,198
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    You could try using htmlspecialchars() instead which converts any special character into a HTML entity, you could then decode the characters back using htmlspecialchars_decode()

  3. #3
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,508
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by john_zakaria View Post
    i want to add slashes to all special character
    Why? When? When you output to the client? When you save in the database?


Bookmarks

Posting Permissions

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