Re: Regex nightmares

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, May 23, 2005 8:43 am, W Luke said:
> I really struggle with regex, and would appreciate some guidance.
> Basically, I have a whole load of files (HTML) which are updated every
> few minutes.  I need to go through each line, looking for the word
> CONFIRMED: (which is always in capitals, and always superseded by a
> colon).  The line looks like this:
>
> 22.5 J.Smith at Thropton, CONFIRMED: more text here, including commas
> and info on the appointment etc

Is that always on ONE line?

If so, you sure don't need anything as fancy as RegEx to do that.

$file = file("/full/path/to/your/file.html") or die("Could not load HTML");
while (list(, $line) = each($file)){
  if (strstr($line, 'CONFIRMED:')){
    $parts = explode('CONFIRMED:', $line);
    list($before, $after) = $parts;
    echo "A CONFIRMED appointment!<br />\n";
    echo "<p>$before</p>\n";
    echo "<p>$after</p>\n";
    echo "<hr />\n";
  }
}

You may need RegEx some other day to pick out the other bits and pieces
from the line...  Or not.  I've done a lot of scraping of data like this
with just explode and strstr and substr.

RegEx is great when you need it; But when you don't it's a lot of overhead
and a bit of a headache.

[Course, when you *DO* need RegEx it's *more* than a bit of a headache. 
More like a migraine :-)]

-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux