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

Strange php code found on my website
I got hacked and the following code was placed within my files:

Code: [Select]<?
/*

Number Format
Hi All,

I have number '000000000050085' I want to format it to 500.85 Can any one give me

New to Arrays
Hi I am new to PHP (a week and a half now) and I am just beginning to read about arrays. I understan

URL Rewrite issue
Im created a series of Rewrites and on page checks to make sure the correct url is being called. But

VAT
how should I deal with VAT?

if I have a product that costs £5.00 and VAT @ 17.5% (£0.87

CURL question
i am wondering if it's possible to use multi curl with login something like

login once to web

help retrieiving results and doing pagination
Having some trouble trying to get the results to show on more than just one page.

What is ha

LOOPing Problem
Hello All!

The following code loops through the data and displays the data accordingly. My p

How to file_get_contents when login required?
Hello!

I am trying to read data from a page that you have to be logged into to view, I am try

unserialize help, getting errors
hi all ,
I got a form with 6 fields (2 input and 4 select box), when the page loads one block is

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