Re: ereg/pattern question
| From: | Wico de Leeuw | Date: | Fri, 01 Dec 2000 17:16:18 +0000 |
| Subject: | Re: ereg/pattern question | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-28227@lists.php.net to get a copy of this message | ||
At 17:53 1-12-00 +0100, Alexander Koeb wrote:
hi all,Or try: elseif (preg_match("'^(.*?)[\s]*=[\s]*(.*)'", $lines[$i], $regs)) { Greetz, WicoLine_6=<FONT color=#800080><B>bye now!</B></FONT> Line_7=</FONT> ......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:]]*)(.*)$",} elseif (ereg("^(.*) = (.*)", $lines[$i], $regs) || ereg("^(.*)=(.*)", $lines[$i], $regs)) { // setting variable $variable = strtolower(trim($regs[1])); $value = trim($regs[2]);$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 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net For additional commands, e-mail: php-general-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net