William Holroyd wrote:[color=blue]
> I've had experience with PHP building simple websites and have only
> scratched the surface of what it's capable of, so in a sense I'm a newbie.
> However the problem I have is that I want to be able to read a file, store
> it into a string, and be able to look for patterns in it to extract. I know
> what the regex expression is for getting the data, but not familiar with how
> to read the string and for each match, store it in an array. I haven't been
> able to find any sample code and my php geek buddy is on vacation.
>
> <?php
>
> $string = implode(file("classes.txt"));
> $string = ereg_replace ("/r|/n", "", $string);
>
> // this is where I have no clue
>
> Regex expression going to be used - "[A-Z]{3,4} [0-9.]{4} [a-zA-Z.
> \n\r]*\(([0-9]|Var.)\) [a-zA-Z;,. \n\r-]*"[/color]
// I didn't look at the regex, just simply copied it here
$regex = "[A-Z]{3,4} [0-9.]{4} [a-zA-Z.\n\r]*\(([0-9]|Var.)\) [a-zA-Z;,. \n\r-]*";
$num = preg_match_all("/$regex/", $string, $found_array);
if ($num === false) exit('Error in preg_match_all().');
echo '<pre>Found ', $num, ' matches: ';
print_r($Found_array);
echo '</pre>';
[color=blue]
> ?>[/color]
Check the fine manual for preg_match_all
http://www.php.net/preg_match_all
--
USENET would be a better place if everybody read: : mail address :
http://www.catb.org/~esr/faqs/smart-questions.html : is valid for :
http://www.netmeister.org/news/learn2quote2.html : "text/plain" :
http://www.expita.com/nomime.html : to 10K bytes :