I attempted to email you, but heres the contents of the email. Enjoy, feel free to email me back comments/problems.
Hola =)
I saw your post on PHPBuilder and was JUST about to post something like that. I am attempting to do very much the same sort of thing. And now that I sat to write this email half an hour ago, I found a lot cleaner solution, using Perl-style regex (much faster than ereg)…
Adapt as you require. :-)
In the HTML file I have:
<Event type=”death” time=”imminent” style=”bloody”>
It is read into the variable $line, whichever way you want to do it.
if(preg_match('/<Event\s(.*?)>/i', $line, $matches)) {
$array = explode(' ', $matches[1]);
$settings = array();
foreach($array as $value)
$newarray[substr($value,0,strpos($value,'"')-1)] = substr($value, strpos($value,'"')+1, -1);
}
After the above code (It is in a loop in my code – I read the file using file() which makes an array… I just test every element of the array), you would get:
Array(
[type] => death
[time] => imminent
[style] => bloody
)
No need to assign additional variables.. its all in one neat array =)
Also, a tip. Since preg is obviously expensive (as far as system clocks)… I use a simple strops before the preg. Ex:
for($i = 0; $i < strlen($file); $i++) {
$line = $file[$i];
if(str_pos(strtolower($line), ‘<event’)===false) {
# Not Found on this line
# The way I do it is this block assigns this line to the “output” variable… it doesn’t contain code we need to
# edit, so we can just tack it on to the output =)
$output .= $line . “\n”; # I think when I did $file = file(‘test.x’); it strips \n\r’s .. let’s add one in to be safe.
continue;
}
# preg here…
}
I hope this helped you out… I sure learned quite a bit from it =)
Ghak