Jump to content

array question


Minase

Recommended Posts

recently i was building a script to parse some values blablabla here is the deal  :P

 

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.