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)
{
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

php form help
Hey,

I use a control file to set my meta tags and titles

Here's an example
Code: &a

PHP switch function help
Hi, I am trying to create a search function for a directory website. On the search function on html

GIS appliction help
I found some tutorials in the internet to develop a map application I don't want to use google maps

Display last record first.
I need some help how put the last record first and first record last.

Thanks

Code: &am

Delete HTML file after loading
I have limited experience with php and its been a year or two since I've last used it. I have a sma

need a script for 3 pages
I have a customer who wants me to set up a site with a number of pages with the following requiremen

Entering Data Problem
Code: $result = mysql_query("SELECT * FROM flights");
while ($row = mysql_fetch_array($

Refining of search Criteria
Dear Friends

I need a help, I have a search page which of cars related, which has different s

Multiple upload and Resize
I would like some help on my script I have the for my index.php

////

<html&

mysql timestamp manipulation
How could I use a timestamp (e.g 2009-10-30 13:20:35 ), and with php find out if it is:

from

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