Results 1 to 4 of 4

Thread: Sigh

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jul 2005
    Posts
    16

    Sigh

    Im getting text via REQUEST from an input box. If I don't format the text in any way and I type a " it will put a \ before it. If i use stripslashes it will work fine. However then when i input \\\\\\\\\\ on the form the output is \\\\\. I tried replaceing \ with %5C but for some reason it echoed the %5C instead of \. I also tried to do:
    $slash = chr(92);
    $test = "S\ite";
    if(strstr($title, "\\\")) {
    $test = str_replace("\\\", "$slash", $test);
    }

    But there is an error. I need 3 \'s don't I? Is there a way to just echo plain text without it being such a problem

  2. #2
    PowerPoster lintz's Avatar
    Join Date
    Mar 2003
    Location
    The 19th Hole
    Posts
    2,697

    Re: Sigh

    You may have to use a loop to remove all the slashes or maybe check the contents on the input box useing javascript and if there are more than 1 / then show a message and don't progress any further until "correct" format is enterd in input box. HTH

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Jul 2005
    Posts
    16

    Re: Sigh

    There is no format and \\ would be allowed. The only thing I'm using to filter that input box is htmlspecialchars...can you tell me more about the loop?

  4. #4
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: Sigh

    The problem you are experiencing is due to a setting in the php.ini called magic quotes. Before using strip slashes you should check whether magic quotes have been turned on. If they have then it would have added the slashes automatically. There is a function which you can use called get_magic_quotes_gpc() which returns true if they are on and false if they are not.

    The function below test this and only uses stripslashes() if magic quotes are on:
    PHP Code:
    function stripslashes_safe($string) {
        if (
    magic_quotes_gpc()) {
            return 
    stripslashes($string);
        } else {
            return 
    $string;

    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

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