[Phpwm] escape hell!

Greg Jones greg.jones at gmail.com
Thu Jun 29 20:03:53 BST 2006


On Thu, 29 Jun 2006 15:58:21 +0100, alan dunn <alan at dunns.co.uk> wrote:

> I have an array  $_arr of  41 elements and about 500 rows, including  
> apostrophes (and other stuff probably!) in some strings. I need to  
> escape the apostrophes and have tried both the following with no success:
>
> $_arr = str_replace(" ' "," \' ",$_arr);
>
> and
>
> foreach ($_arr as $_arr2){
>                         foreach ($_arr2 as $var){$var =  
> addslashes($var);}
>                     }
> can anyone help out?
> thanks, alan dunn

When you use foreach, it operates on a copy of the array, not on the array  
itself.

Your code would need to be changed to:
foreach($arr as $key=>$arr2) {
   foreach($arr2 as $key2=>$var) {
     $arr[$key][$key2]=addslashes($var);
   }
}

Greg

-- 
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/



More information about the Phpwm mailing list