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

split string
Hi all

i have some names (imploded by comma):
Code: toronto,paris,madrid
Now, i would

Images in email problem
I found this script for sending emails, it works but if the email has <img src="image.jp

rename the file
File.txt

Code: ***DOCUMENT***
..DN:
000044255
..CB:
..SN:
..PY:
2009
..E

Dynamic memory problem
Hey,

At the beginning of my code, I have this line:

Shape* gShape = 0;

How can you detect variable string in a massive string?
Ok guys, i need some help with this one.

I am going to be getting a large string, like 10-20

Checkbox info wont include in Mailto
Hey, im new to php.
Basically I have made a form to request which type of job(s) are needed, whic

gmmktime or mktime
I live in the UK, i am within the GMT (with daylight saving time ie 1 hour difrence between summer a

cURL error
So here is my code... I got it off of here... http://www.youtube.com/watch?v=XcgQUsorF_8
Because

form class help (oop php5)
Hidy Ho Neighbors,

I'm forcing myself to learn oop/classes for php5. It seems like a good id

styling a RadioButtonList
HiI need to have a radio button and close to it, its lable, then a space then another set of those.

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