amedhussaini Posted April 21, 2008 Share Posted April 21, 2008 Hey all, Well, I'm starting to write some of my 'display_results.php' and i'm happy to see that slashes are in fact being added in ("hi i\'m here yay"). obviously i now want to get rid of em before i spit em out to be seen. is there already an algorithm/function out there that will remove_slashes() for an entire array? eg. $result = mysqli_query($mysqli, $random_query); $result_in_array = mysqli_fetch_assoc($result); remove_slashes($result_in_array); ? Thanks in advance! Link to comment https://forums.phpfreaks.com/topic/102070-removing-slashes-from-arrays/ Share on other sites More sharing options...
DarkWater Posted April 21, 2008 Share Posted April 21, 2008 Hey all, Well, I'm starting to write some of my 'display_results.php' and i'm happy to see that slashes are in fact being added in ("hi i\'m here yay"). obviously i now want to get rid of em before i spit em out to be seen. is there already an algorithm/function out there that will remove_slashes() for an entire array? eg. $result = mysqli_query($mysqli, $random_query); $result_in_array = mysqli_fetch_assoc($result); remove_slashes($result_in_array); ? Thanks in advance! Use stripslashes($array) on anything you want to output that has slashes. Like: <?php echo stripslashes($result_in_array['comment']); ?> For example. =P Link to comment https://forums.phpfreaks.com/topic/102070-removing-slashes-from-arrays/#findComment-522514 Share on other sites More sharing options...
redarrow Posted April 21, 2008 Share Posted April 21, 2008 <?php $a=array("member/","joh/n","redarr/ow"); foreach($a as $res){ $result=str_replace("/","",$res); echo "$result <br>"; } ?> Link to comment https://forums.phpfreaks.com/topic/102070-removing-slashes-from-arrays/#findComment-522518 Share on other sites More sharing options...
DarkWater Posted April 21, 2008 Share Posted April 21, 2008 <?php $a=array("member/","joh/n","redarr/ow"); foreach($a as $res){ $result=str_replace("/","",$res); echo "$result <br>"; } ?> Wrong slash. He needs to remove \ from escaping chars. He can just use stripslashes(). Or this: <?php function striparrayslash($array) { foreach ($array as $k=>$v) { $array[$k] = stripslashes($v); } return $array } //usage: $newarray = striparrayslash($oldarray); print_r($newarray); ?> Should work. Tell me if there are any errors and I'll fix them. Link to comment https://forums.phpfreaks.com/topic/102070-removing-slashes-from-arrays/#findComment-522525 Share on other sites More sharing options...
redarrow Posted April 21, 2008 Share Posted April 21, 2008 Sorry was only trying to help with an example.......... Link to comment https://forums.phpfreaks.com/topic/102070-removing-slashes-from-arrays/#findComment-522531 Share on other sites More sharing options...
DarkWater Posted April 21, 2008 Share Posted April 21, 2008 Just tried it on my server and found a tiny error. This function works 100%. =) <?php function striparrayslash($array) { foreach ($array as $k=>$v) { $array[$k] = stripslashes($v); } return $array; } //usage: $oldarray = array("test"=>"lo\\l"); //I escaped the backslash so it displays in the array. =) $newarray = striparrayslash($oldarray); print_r($newarray); ?> Link to comment https://forums.phpfreaks.com/topic/102070-removing-slashes-from-arrays/#findComment-522534 Share on other sites More sharing options...
amedhussaini Posted April 21, 2008 Author Share Posted April 21, 2008 thank you so much everyone! cheers, amed Link to comment https://forums.phpfreaks.com/topic/102070-removing-slashes-from-arrays/#findComment-522537 Share on other sites More sharing options...
DarkWater Posted April 21, 2008 Share Posted April 21, 2008 Any time. Always feel free to ask if you need help. Link to comment https://forums.phpfreaks.com/topic/102070-removing-slashes-from-arrays/#findComment-522539 Share on other sites More sharing options...
Fadion Posted April 21, 2008 Share Posted April 21, 2008 Just another approach for fun <?php function stripthoseslashes(&$input){ stripslashes($input); } $arr = array("me\\","you\\","hi\\"); array_walk($arr, 'stripthoseslashes'); print_r($arr);?> Link to comment https://forums.phpfreaks.com/topic/102070-removing-slashes-from-arrays/#findComment-522547 Share on other sites More sharing options...
DarkWater Posted April 21, 2008 Share Posted April 21, 2008 Just another approach for fun <?php function stripthoseslashes(&$input){ stripslashes($input); } $arr = array("me\\","you\\","hi\\"); array_walk($arr, 'stripthoseslashes'); print_r($arr);?> You could do that. I don't like array_walk() for whatever reason, though. Link to comment https://forums.phpfreaks.com/topic/102070-removing-slashes-from-arrays/#findComment-522548 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.