Re: ereg/pattern question

From: Date: Fri, 01 Dec 2000 16:23:40 +0000
Subject: Re: ereg/pattern question
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-28216@lists.php.net to get a copy of this message
Hi David: > Line_6=<FONT color=#800080><B>bye now!</B></FONT> > Line_7=</FONT> > ...... > } elseif (ereg("^(.*) = (.*)", $lines[$i], $regs) > || ereg("^(.*)=(.*)", $lines[$i], $regs)) { > // setting variable > $variable = strtolower(trim($regs[1])); > $value = trim($regs[2]); The problem you ran into is the last "=" was being matched rather than the first due because "=" is matched by (.*). Also, you can accomplish the same thing, more accurately, with one expression by adding a middle atom. This new middle atom catches both spaces, no spaces and tabs in any combination. if ( ereg("^([[:alnum:]_]*)([[:space:]]*=[[:space:]]*)(.*)$", $lines[$i], $regs) ) { You'll then need to substitute $regs[3] for $regs[2] in the last line of your code. Enjoy, --Dan -- PHP scripts that make your job easier http://www.analysisandsolutions.com/code/ SQL Solution | Layout Solution | Form Solution T H E A N A L Y S I S A N D S O L U T I O N S C O M P A N Y 4015 7 Ave, Brooklyn NY 11232 v: 718-854-0335 f: 718-854-0409

« previous php.general (#28216) next »