smith.james0 Posted December 24, 2006 Share Posted December 24, 2006 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 meMany thanks James Link to comment https://forums.phpfreaks.com/topic/31760-stripping-from-a-value-in-a-3d-array/ Share on other sites More sharing options...
kenrbnsn Posted December 24, 2006 Share Posted December 24, 2006 The correct function is htmlentities(), but instead of that function, you should use the [url=http://www.php.net/mysql_real_escape_string]mysql_real_escape_string()[/url] function.Ken Link to comment https://forums.phpfreaks.com/topic/31760-stripping-from-a-value-in-a-3d-array/#findComment-147294 Share on other sites More sharing options...
smith.james0 Posted December 25, 2006 Author Share Posted December 25, 2006 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 helpThanks James Link to comment https://forums.phpfreaks.com/topic/31760-stripping-from-a-value-in-a-3d-array/#findComment-147503 Share on other sites More sharing options...
kenrbnsn Posted December 25, 2006 Share Posted December 25, 2006 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 Link to comment https://forums.phpfreaks.com/topic/31760-stripping-from-a-value-in-a-3d-array/#findComment-147524 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.