Hi, I have a case which is adding underlines in the place of spaces but i cannot see what the cause is? This is the case: case 'update': if ($cart) { $newcart = ''; foreach ($_POST as $key=>$value) { if (stristr($key,'qty')) { $id = str_replace('qty','',$key); $items = ($newcart != '') ? explode(',',$newcart) : explode(',',$cart); $newcart = ''; foreach ($items as $item) { if ($id != $item) { if ($newcart != '') { $item = ''; $newcart .= ','.$item; } else { $item = ''; $newcart = $item; } } } for ($i=1;$i<=$value;$i++) { if ($newcart != '') { $newcart .= ','.$id; } else { $newcart = $id; } } } } } $cart = $newcart; break; PHP: Can anyone see where the problem is? Cheers, Adam
Underlines? Explain. You may want to do a view source in HTML mode as it may be some HTML that is not closed </u> (before the results of that PHP snippet) Otherwise, show us the input you have ($_POST, $cart), expected output, and what you now receive as output.
Before the value is passed to the update it is like this: 56:Size|Large (68cm x 43cm) - 11.95|11.95 Code (markup): And after it looks like this: 56:Size|Large_(68cm_x_43cm)_-_11_95|11_95 Code (markup):
Well, you're not using any underscores in that piece of code. Are you sure that's where the error is generated?
How can it replace spaces with underscores if this code piece doesn't have anything like that? Same question as premiumscripts, but if it's the only thing that it is being passes to you shouldn't be getting '56:Size|Large_(68cm_x_43cm)_-_11_95|11_95'. Also I didn't get what the error is...?
I know that is why i cannot see where the problem is... The error is that i don't want the _ in the string.
Well, it certainly isn't in that piece of code. Post the entire script. Also, what output are you expecting? The exact same as the input?
This is a PHP bug. What version are you running? change your request / post / get method and see if that makes any difference OR use string replace to get the values back.
^Looks like a PHP bug then Just simply replace them then at the end of the code then: $cart = preg_replace("/_/i", " ", preg_replace("/(\d+)_(\d+)/i", "$1.$2", $newcart)); Code (markup):