array_map() probably obvious mistake


Posted on 16th Feb 2014 07:03 pm by admin

The code below is part of a class to escape strings, but should also accept an array, using array_map() to do the job. Unfortunately, passing an array results in the original, unescaped array being returned - can't figure out why? If you uncomment the echo statement, it is outputting the correct escaped string for each element of the array, so the callback is definitely happening.

public function escape_str($str)
{
Did you know?Explore Trending and Topic pages for more stories like this.
if (is_array($str))
{
array_map(array('MYSQL_DB','escape_str'),$str);
}
else
{
if (get_magic_quotes_gpc()) {
$str = stripslashes($str);
}
if (!is_numeric($str)) {
$str = "'" . mysql_real_escape_string($str) . "'";
//echo $str.'<br />';
}
}
return $str;
}

Example:
$xt = array("' OR ''=''",'"abcdefg"');
print_r($db->escape_str($xt));

Outputs original array, not escaped!

Can anyone help with this? Thanks.
No comments posted yet

Your Answer:

Login to answer
204 Like 21 Dislike
Previous forums Next forums
Other forums

Help with email validation please...
Hi,
Please could you help.
I have a register.php login page where users register, the detail

Need understanding of this bit of code
Code: <?php
// WHERE clause filters
$arrSQLFilters = array();

//

Running a cron job through PHP/Apache?!
Hello all,
I have a PHP script which makes a cron file from user input. When i try to run the cro

Change snippet to use CURDATE
I am using time() in the snippet below, I would like to use CURDATE() and have the database setup fo

Which practice of iteration through containers is preferred
In the "real world" what kind of loop do most people use to iterate through a container like a vecto

problems with search form numerical "between" sending by php
I am trying to display the results of a search, on a sql database, on a web page. I set up html &quo

keeps going back to index.html ???????
ok so i started making my site using mostly.html files now i have added a fair chunk of php. My inde

Check premium expire
Hi,

I am making a simple file hosting site and want to check if users premium subscriptions h

Need PHP help... have all the elements... just need help putting them together :
Hey Guys,

I was wondering if someone could help me. I am doing a website for a client which

Limiting checkboxes?
Hi guys,

I have this code: Code: if(isset($_POST['selected'])) {
foreach($_POST['selec

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash