0

I have a mysql result array and I'm trying to stripslashes on the array using array_walk. It's not stripping slashes from mysql. It is working on the array I manually added ($dataArr['xxx']) though.

Here is my code:

$sql = ' select * from `ads` where id = 3 ';
$res = mysql_query($sql, $conn) or die(mysql_error());
$row = MYSQL_FETCH_ASSOC($res);

$dataArr = $row;

$dataArr['xxx'] = '<script type=\'text/javascript\'><!--//<![CDATA[
           var m3_u = (location.protocol==\'https:\'?\'https://ads.test.com/www/delivery/ajs.php\':\'http://ads.test.com/www/delivery/ajs.php\');
           var m3_r = Math.floor(Math.random()*99999999999);
           if (!document.MAX_used) document.MAX_used = \',\' etc.... etc....;
         ';
array_walk_recursive($dataArr, 'stripslashes');
print '<pre>'; print_r($dataArr); print '</pre>';
EricP
  • 1,459
  • 6
  • 33
  • 55

1 Answers1

0

Some recommendations:

1) Remove the leading and ending spaces in your query.

2) mysql_fetch_assoc should be in lowercase.

3) Bare in mind that mysql_fetch_assoc only returns one row at a time. You need to work with a while loop to fetch all the results. See examples in the documentation.

4) You might prefer to use mysql_fetch_array instead of mysql_fetch_assoc. See here.

El Barto
  • 919
  • 1
  • 5
  • 18
  • Sorry, I meant to say it's not stripping the slashes. It is returning the results. – EricP Mar 11 '12 at 22:07
  • You don't seem to need recursive behaviour... why don't you try with `array_walk` or `array_map`? Also, try with `mysql_fetch_array` in case there's something about associative arrays which might be bothering. – El Barto Mar 11 '12 at 22:12
  • I tried array_walk and array_map and they both are not stripping the slashes. thanks – EricP Mar 11 '12 at 22:19