[Phpwm] escape hell!
Phil Beynon
phil at infolinkelectronics.co.uk
Thu Jun 29 20:41:59 BST 2006
> > 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
>
Depends what the array is part of, but if its going to a database or something then why not use htmlentities() to replace the apostrophes etc, that should make it safe enough.
Regards,
Phil
More information about the Phpwm
mailing list