Jump to content

Stripping ' from a value in a 3d array


smith.james0

Recommended Posts

I need to strip ' from a value in a 3d array and then put it back in again, it stop it causing problems when inserting into the db.

my current array

[code]
Array
(
    [7] => Array
        (
            [0] => 1166832000
            [1] => 67889
            [2] => -7.8
            [3] => 7689
            [4] => -879
            [5] =>
            [6] => 1
            [7] =>
            [8] => 678,98
            [9] => 9
            [10] => 78.98
            [11] => 8.90
            [12] => & small text with ' in it > <
            [13] => Sat
            [14] => 51
            [15] => 2006
            [16] =>
            [17] =>
        )
[/code]
my current code

[code]foreach ($_POST as $key => $book){

$commenta = $_POST[$key][12];
$commentb = strtoupper(htmlspecialchars ("$commenta", ENT_QUOTES));

$_POST[$key][12] = $commentb;
}

[/code]

Output
[code]
Array
(
    [7] => Array
        (
            [0] => 1166832000
            [1] => 67889
            [2] => -7.8
            [3] => 7689
            [4] => -879
            [5] =>
            [6] => 1
            [7] =>
            [8] => 678,98
            [9] => 9
            [10] => 78.98
            [11] => 8.90
            [12] => & SMALL TEXT WITH ' IN IT > <
            [13] => Sat
            [14] => 51
            [15] => 2006
            [16] =>
            [17] =>
        )
[/code]
The strtoupper is working, but the htmlspecialchars isn't, is this something i have done wrong?

Can anyone help me
Many thanks James
Link to comment
https://forums.phpfreaks.com/topic/31760-stripping-from-a-value-in-a-3d-array/
Share on other sites

I have tried both htmlentities()

            [12] => & small text with ' in it > <

[code]foreach ($_POST as $key => $book){

$commenta = $_POST[$key][12];

$commentb = htmlentities($commenta, ENT_QUOTES);

$_POST[$key][12] = $commentb;
} [/code]

outputs
            [12] => & small text with ' in it > <

It's not been changed.

mysql_real_escape_string() does not / in front of the '

Can anyone help

Thanks James
You need to look at the generated source of the page you're looking at, since the web browser reinterprets the string and displays it "correctly".

The mysql_real_escape_string() function only escapes the characters prior to doing the database function, the backslash is not actually entered with the value in the database.

Ken

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.