Re: ereg/pattern question

From: Date: Fri, 01 Dec 2000 16:53:56 +0000
Subject: Re: ereg/pattern question
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-28224@lists.php.net to get a copy of this message
hi all, > > 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 also could do something like } elseif (ereg("^([^=]*) = (.*)", $lines[$i], $regs) || ereg("^([^=]*)=(.*)", $lines[$i], $regs)) { to match only the first '=' in the line... greetings alex

« previous php.general (#28224) next »