Re: Comparing string to array

From: Date: Tue, 19 Jun 2007 12:49:53 +0000
Subject: Re: Comparing string to array
References: 1 2 3 4 5 6 7  Groups: php.general 
Request: Send a blank email to php-general+get-257395@lists.php.net to get a copy of this message
Richard Davey wrote:
Hi Stut, Tuesday, June 19, 2007, 1:16:54 PM, you wrote:
The problem is finding a way to expand the input name (which is a string) into a format that $_POST can be searched for. Or do the reverse, iterate through $_POST to find a match for the input name and get that value.
Try this overly commented snippet on for size... http://dev.stut.net/php/davey.php
Very nice, thank you. I was hoping there would be a way to do it without resorting to eval(), but if even you can't figure out how, I'm not going to waste any more time trying to either :)
You probably could by breaking it into each part and then using a loop to descend to the right place, but I don't think that's going to be any better than using eval. I'm assuming the source for $target is trusted. If not then you'll want to sanitise it further by removing anything that's not a-z, 0-9 and [] just to ensure no dodgy code can be inserted.
I loved this part: // The target - offensive American spelling! :) Cheers,
No probs. -Stut -- http://stut.net/

« previous php.general (#257395) next »