Jump to content

[SOLVED] stripping back slashes


Hardwarez

Recommended Posts

I have used mysql_real_escape_string() on all data that is input and stored in my db. 

 

I am using this; in a edit form.

<input type="text" size="25" MAXLENGTH="100" name="client'.$i.'" value="';
$client=$row['client'];
$client=stripslashes($client);
echo $client . '"' . $j . '>

 

Stripslashes() seems to not work.  The out put goes to the first \ and stops; showing the first back slash.

 

Ie If the client name is

Mr "Big"
.  Then the output is
Mr \

 

Link to comment
https://forums.phpfreaks.com/topic/76666-solved-stripping-back-slashes/
Share on other sites

try this function

 

<?php

function no_slashes($array)
    {
        foreach($array as $key=>$value)
            {
                if(is_array($value))
                    {
                        $value=no_slashes($value);
                        $array_temp[$key]=$value;                        
                    }
                else
                    {
                        $array_temp[$key]=stripslashes($value);
                    }
            }        
        return $array_temp;    
    } 

?>

When formatting text containing quotes to go to the browser, you have to use the htmlentities() function:

<?php
echo '<input type="text" size="25" MAXLENGTH="100" name="client'.$i.'" value="' . htmlentities($row['client'], ENT_QUOTES) .'"' . $j . '>';
?>

 

Ken

The reason why its needed: You enclose the value of your text box in double quotes, yet your value contains a double quote. So, the browser gets confused. Is it the value supposed to terminate with the first double quote it comes across? That is what it does - it doesn't 'nest' the double quotes - afterall, what would happen if the value contained a single double quote.

 

Therefore, we use the html character codes for the quotes inside things like values of elements.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.