Re: Getting Results from function; snickers != buttery !

From: Date: Thu, 16 Nov 2000 06:54:09 +0000
Subject: Re: Getting Results from function; snickers != buttery !
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-25639@lists.php.net to get a copy of this message
On Wed, 15 Nov 2000, Kevin Leavell wrote: > Thanks for working with me here but I need a little more help. > > > $value=ereg_replace('[^>]*value="([^"]+)">','\\1',$string); > > Makes snickers = goodbaduglybuttery > I need > snickers = good > marsbar = bad > peppermintpatty = ugly > butterfinger = buttery > > > Here is the original code: > > $string='<input type="hidden" name="snickers" > value="good"> > <input type="hidden" name="marsbar" value="bad"> > <input type="hidden" name="peppermintpatty" value="ugly"> > <input type="hidden" name="butterfinger" > value="buttery">'; > > $key=ereg_replace('<input type="hidden" > name="([^"]+)".*','\\1',$string); > $value=ereg_replace('.*value="([^"]+)">','\\1',$string); > $$key=$value; > print $snickers; > > Thanks again, > Kevin > > BTW - thanks for the tip on monospace fonts. Now everyones sig will look > much better :) > I've found that the only way to do it is as follows: $input=$string; while (ereg("^((.|\n)*)<input type="hidden" name="(([^"])*)" value="(([^"])*)">((.|\n)*)$", $input, $output)) { $input=$output[1].$output[7]; ${$output[3]}=$output[5]; }; Try that, taking the two stinking newlines as single spaces instead. Trust me, I had to build a custom pseudo-XML parser by hand this way :( -- Ignacio Vazquez-Abrams <ignacio@openservices.net>

« previous php.general (#25639) next »