views:

33

answers:

3

I have simple form posting to another file. The problem I'm having is with TEXTAREA field.

In the form TEXTAREA, I enter this:

<h1 class="padlock">Member Login</h1>

and the Output is on the other page when echo with PHP:

<h1 class=\"padlock\">Member Login</h1>

It's automatically escaping characters. I'm displaying the output in another TEXTAREA box.

How can I make it be exactly the same?

+1  A: 

Magic Quotes is on.

This is a deprecated feature of PHP. It was used to escape all incoming user data. You can use stripslashes() to get the original data back:

if (get_magic_quotes_gpc()) {
    $_POST['textareaname'] =stripslashes($_POST['textareaname']);
}

or to apply this to the entire $_POST array:

function stripslashes_recursive($data){
  if(is_array($data){
    $new_data = array();
    foreach($new_data as $key => $entry){
      $new_data[$key] = stripslashes_recursive($entry);
    }
    return $new_data;
  } else { 
    return stripslashes($data);
  }
}

if (get_magic_quotes_gpc()) {
    $stripped_postdata = stripslashes_recursive($_POST);
}

Note: the recursive function is used to support arrays in your post data.

Scharrels
A: 

Ups... stripslashes !

Codex73
A: 

Use this at the top of scripts that accept $_POST variables:

if (get_magic_quotes_gpc()){
  foreach ($_POST as $key=>$val){
    $_POST[$key] = stripslashes($val);
  }
}

Some versions of PHP escape automatically and it's a real pain. Future versions do not.

Al