This problem is much better solved by changing the names of the elements in your form to code.
This problem is much better solved by changing the names of the elements in your form to code. For example, where you now have let's say You would change that to After doing this, $_GET'code' will be an array which contains all the values from the text boxes as its items. Update: If you cannot control the names of the incoming parameters, you need to parse manually.
Here's how I would do it: // Sample data $get = array('code_1' => 'foo', 'code_2' => 'bar', 'code_X' => 'X', 'asdf' => 'X'); $codes = array(); foreach($get as $k => $v) { // Reject items not starting with prefix if (substr($k, 0, 5)! = 'code_') { continue; } // Reject items like code_X where X is not all digits $k = substr($k, 5); if (!ctype_digit($k)) { continue; } $codes$k = $v; } print_r($codes).
I agree, and if I created the 'cart' myself, this is how I would have done it. Rather than $_GET'code' I would have posted the data. I just need to get something up quickly, and then improve on it from there.
Thanks for the help! – Fleppar Dec 7 at 15:15 @Fleppar: I added an alternative for this situation. – Jon Dec 7 at 15:43 With the update, I'll put you as the correct answer since you better explained what you should do AND how to do it if you have no other option.
Thanks for the help. – Fleppar Dec 7 at 15:53.
It would be much better to use an array like Jon suggested. It also would be cleaner to not use get for this. But rather post.
However if you really want to go this route you could do: foreach($_GET as $name=>$value) { if (strpos($name, 'code_')! == 0) continue; // here are the names and values of the items } However again: I would not recommend it.
Agree, not recommended – Zulkhaery Basrul Dec 7 at 15:06 I agree, I am using jcart and without heavy modification to the code itself - it seems like the quickest way to get it going. I do not really need anything secure right away as the website is closed only to internal employees. I will take your advice and eventually recode the cart and post data.
– Fleppar Dec 7 at 15:11 Your code match some characters too like "code_test" will match too. So it is better to use regular expression like "^code_1-9$" to get the exact filtering. – shantha Dec 7 at 15:17.
Print_r($_GET); foreach($_GET as $key=>$val) { echo ''; echo $key. ' : '. $val; }.
You have to iterate through $_GET and look for names. Foreach(!empty($_GET as $name=>$value)) { // Check for match names for your if (preg_match('/^code_1-9$/', $name)) { // Do whatever with values } }.
1 ereg has been deprecated as of PHP 5.3.0. Use preg_match instead. – Jon Dec 7 at 15:43 @Jon Thanks and I have updated the post.
– shantha Dec 7 at 15:50.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.