Reply to Re: [PHP] Regex nightmares

Your name:

Reply:


Posted by "Richard Lynch" on 05/24/05 09:44

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

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация