Re: [Q] Regex Woes

From: Date: Sun, 18 Jul 2004 21:59:00 +0000
Subject: Re: [Q] Regex Woes
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-190939@lists.php.net to get a copy of this message
Michael T. Peterson wrote:
I need to find all lines that begin with the string 'WAZ' after reading from a url (http://www.atmos.washington.edu/data/zone_report.KSEW.html). While I've tried every combination of expressions under the sun (using the functions preg_match(), ereg()), I can not figure out a correct regexp for this task.
This works. Read the entire file into a string (file_get_contents() works great here) and pass to this regex. $matches[0] will have your lines that start with WAZ. Example: <?php $file = "asdf asdf asdf WAZ this is line 1 asdf asdf asdf asdf WAZ this is another line that should be matches fWAZ this is a line that shouldn't be matches WAZ one more for good measure and a bad one WAZ (whoa, who put that there!) asdf asdf asd fas df asdf"; preg_match_all('/^WAZ.*/m',$file,$matches); print_r($matches[0]); ?> -- ---John Holmes... Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/ php|architect: The Magazine for PHP Professionals – www.phparch.com

« previous php.general (#190939) next »