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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.