Minase Posted March 30, 2010 Share Posted March 30, 2010 recently i was building a script to parse some values blablabla here is the deal foreach($variable as $a => $b) { echo addslashes($b); } that little script doesnt work... i mean the loop is fine but it doesn't add slashes :| if i print_r the array i get something like this [0] => waz'ap [1] => another's page etc you get the idea... this little problem made my wonder why it didnt work... if i add slashes to a normal string it does work so it's not a php compile error... thanks Link to comment https://forums.phpfreaks.com/topic/197046-array-question/ Share on other sites More sharing options...
premiso Posted March 30, 2010 Share Posted March 30, 2010 Are you meaning to echo it, or do you want to re-assign the escaped data to the array? If the latter this is why: foreach($variable as $a => $b) { $variable[$a] = addslashes($b); } Will assign the addslashes version of $b and print it out properly. Link to comment https://forums.phpfreaks.com/topic/197046-array-question/#findComment-1034406 Share on other sites More sharing options...
Minase Posted March 30, 2010 Author Share Posted March 30, 2010 just a simple echo with escaped data nothing more ,nothing less Link to comment https://forums.phpfreaks.com/topic/197046-array-question/#findComment-1034409 Share on other sites More sharing options...
Minase Posted March 30, 2010 Author Share Posted March 30, 2010 sorry but i cant edit the post above. it does seem that if i use a normal array like $arr = array("tes's","be'ss"); foreach($arr as $a) { echo addslashes($a); } it does work,but if i use an array generated by preg_match_all it doesnt... preg_match_all($a_preg,$asd,$some_array); foreach($some_array[2] as $value => $value2) { echo addslashes($value2)."<br>"; } if i print the array nothing weird,everything is fine,even the $value2 is correct but the slashes doesn't add ... :| Link to comment https://forums.phpfreaks.com/topic/197046-array-question/#findComment-1034413 Share on other sites More sharing options...
Minase Posted March 31, 2010 Author Share Posted March 31, 2010 no one? Link to comment https://forums.phpfreaks.com/topic/197046-array-question/#findComment-1034559 Share on other sites More sharing options...
Minase Posted March 31, 2010 Author Share Posted March 31, 2010 no one really? please really need this. Link to comment https://forums.phpfreaks.com/topic/197046-array-question/#findComment-1034866 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.