weird backslash escape character occurs

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kuzure
    New Member
    • Dec 2006
    • 48

    weird backslash escape character occurs

    Dear friends,

    I had used php to store data to a file, for instance,"testi ng.txt". But there is one problem, there are funny characters occur when it store in the file.

    In my web page, it has text boxes. One of the text box is to insert the address of a file. For instance, C:\Documents and Settings\Yahoo\ YourFile.txt

    But, when it comes to store this address, it appear this in the text file, C:\\Documents and Settings\\Yahoo \\YourFile.txt

    Notice there are double backslashes at the address.

    Other like phone number or name, For instance, Arnold Schwarzenegger and 62725603 have no problem, it can store in file without any extra character.

    Hope someone can give me some clue to solve it.

    Appreciate for any reply. Thank you.

    Best Regards.
  • cassbiz
    New Member
    • Oct 2006
    • 202

    #2
    You need to use stripslashes()

    for example:

    Code:
    <?php
    $str = "Is your name O\'reilly?";
    
    // Outputs: Is your name O'reilly?
    echo stripslashes($str);
    ?>
    You can take a look at the tutorial here from php.net

    Good Luck

    Comment

    • ronverdonk
      Recognized Expert Specialist
      • Jul 2006
      • 4259

      #3
      Non standard characters, like double and single quotes, backslashes and NULL are escaped by the server using your using the escape character \ (backslash).

      For information on how strings behave, especially with regard to usage of single quotes, double quotes, and escape sequences, see the Strings entry in the Types section of the PHP manual at http://nl3.php.net/manual/en/language.types.string.php

      Ronald :cool:

      Comment

      • kuzure
        New Member
        • Dec 2006
        • 48

        #4
        Originally posted by cassbiz
        You need to use stripslashes()

        for example:

        Code:
        <?php
        $str = "Is your name O\'reilly?";
        
        // Outputs: Is your name O'reilly?
        echo stripslashes($str);
        ?>
        You can take a look at the tutorial here from php.net

        Good Luck
        Hrm, What you telling me is correct, but thats not what I really wanted. In the examples you guys provide, the extra character will appear when it involve ( \ ), ( " ) and ( ' ). Also, it only appear in the command "echo", didnt explain what will happen when it store in .txt.

        Do you have any idea to store it in .txt without the extra character?

        Best Regards.

        Comment

        • kuzure
          New Member
          • Dec 2006
          • 48

          #5
          Originally posted by cassbiz
          You need to use stripslashes()

          for example:

          Code:
          <?php
          $str = "Is your name O\'reilly?";
          
          // Outputs: Is your name O'reilly?
          echo stripslashes($str);
          ?>
          You can take a look at the tutorial here from php.net

          Good Luck

          Beside, I'm using a "browse" button to search the file I wanted. If I am the one to use the web page, of course, I might able to avoid this error, since I know what should be added in order to avoid it. But what about other user? They have no idea how's happening and the error keeps poping out since the address has double slashes.


          Best Regards.

          Comment

          Working...