PHP gurus: inserting escape characters into editing field

Discussion in 'OT Technology' started by ZeroDeeFeX, Mar 25, 2005.

  1. ZeroDeeFeX

    ZeroDeeFeX OT Supporter

    Joined:
    Oct 9, 2002
    Messages:
    5,087
    Likes Received:
    0
    Location:
    Sunnyvale, CA
    I have a textarea which I use to load up html pages for editing in php. The problem I am running into is that every time I load an html page into the editor and save it, it inserts escape characters into the html before the quotes. That is a problem because the html page displays those \. I know I have had this problem in the past and there was a simple fix, but does anyone know off the top of their head what the heck could be causing this?
     
  2. ZeroDeeFeX

    ZeroDeeFeX OT Supporter

    Joined:
    Oct 9, 2002
    Messages:
    5,087
    Likes Received:
    0
    Location:
    Sunnyvale, CA
    please... someone!
     
  3. Bono

    Bono Guest

    Your problem is caused by a "feature" called magic quotes. Most of the time, you will want to stripslashes() each element of $_GET, $_POST and $_COOKIE if get_magic_quotes_gpc() returns true at runtime on your server (it often will, unfortunately).

    I think this is what you are trying to accomplish:

    PHP:
    <?php
        
        
    function array_strip_byref(&$input) {
        
            foreach(
    $input as &$element) {
            
                if(!
    is_array($element))
                
                    
    $element stripslashes($element);
                    
                else
                
                    
    array_strip_byref($element);
                    
            }
            
            return;
            
        }
        
        
        
        if(
    get_magic_quotes_gpc()) {
        
            
    array_strip_byref($_GET);
            
    array_strip_byref($_POST);
            
    array_strip_byref($_COOKIE);
            
        }
        
        
        
    /* ... */
        
    ?>
     
  4. ZeroDeeFeX

    ZeroDeeFeX OT Supporter

    Joined:
    Oct 9, 2002
    Messages:
    5,087
    Likes Received:
    0
    Location:
    Sunnyvale, CA
    awesome! Thank you!!!
     

Share This Page