ereg/pattern question
| From: | David P. Schwartz | Date: | Fri, 01 Dec 2000 11:39:44 +0000 |
| Subject: | ereg/pattern question | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-28190@lists.php.net to get a copy of this message | ||
I've got some unexpected things happening in an apparently straightforward bit
of code.
Take some lines from an INI-file that look like this:
--------------------------------------------------------------------
[editbox]
Lines=8
Line_0=<FONT size=3 color=#000000 face="Times New Roman">
Line_1=<CENTER>
Line_2=<FONT size=5 color=#FF0000 face="Arial"><B><U>This is a test
heading.</B></U></FONT></CENTER>
Line_3= <BR>
Line_4=Here is a <FONT><U>line</U></FONT> with <FONT
face="Arial">some</FONT>
font <FONT><B>changes</B></FONT> in it.<BR>
Line_5= <BR>
Line_6=<FONT color=#800080><B>bye now!</B></FONT>
Line_7=</FONT>
--------------------------------------------------------------------
A bit of code that's parsing it looks like this:
--------------------------------------------------------------------
} elseif (ereg("^\[(.*)\]", $lines[$i], $regs)) {
// new section
$section = strtolower(trim($regs[1]));
$iniCachedSections[$filename][] = trim($regs[1]);
} elseif (ereg("^(.*) = (.*)", $lines[$i], $regs)
|| ereg("^(.*)=(.*)", $lines[$i], $regs)) { // <<---
// setting variable
$variable = strtolower(trim($regs[1]));
$value = trim($regs[2]);
if (ereg("^[\"'](.*)[\"']$", $value, $regs)) {
$value = $regs[1];
}
--------------------------------------------------------------------
The line in the middle that tests for equal signs ('=') ends up returning a
$value string that's empty for each of the lines above that contain more than
one '=' (ie., Line_0, Line_2, Line_4, and Line_6).
Either I've got the wrong patterns or the wrong function. What I want is to
split a line like "Line_6=<FONT color=#800080><B>bye
now!</B></FONT>" into:
$variable = "Line_6";
$value = "<FONT color=#800080><B>bye now!</B></FONT>";
Any suggestions?
Thanks
-David Schwartz