Re: Getting Results from function; snickers != buttery !
| From: | Mark Maggelet | Date: | Thu, 16 Nov 2000 08:59:03 +0000 |
| Subject: | Re: Getting Results from function; snickers != buttery ! | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-25657@lists.php.net to get a copy of this message | ||
On Thu, 16 Nov 2000 01:54:09 -0500 (EST), Ignacio Vazquez-Abrams
(ignacio@openservices.net) wrote:
>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
>:(
ouch.
this is what I had in mind, maybe you'll think it's cleaner:
<?
$lines=explode("\n",$string);
for($i=0;$i<sizeof($lines);$i++){
$key=ereg_replace('<input type="hidden"
name="([^"]+)".*','\\1',$lines[$i]);
$value=ereg_replace('.*value="([^"]*)">','\\1',$lines[$i]);
$$key=$value;
}
?>
- Mark