Jump to content

need some help regarding regex and webpage


james_4k2

Recommended Posts

Hi to all,

            I am a new php programmer and I am stuck with a problem.

<?php

$f=fopen("http://www.health.gov.on.ca/english/providers/program/ohip/sob/schedule_master.html","r");

?>

 

My task is to write a script which will go to the above mentioned link and then search for the effective date. Currently if you visit the website then the effective date is June 5, 2008. I also have a database which has current date and new date column. so my script should search this website everyday and match it with the database. If the new effective date is different from current date stored in db then it should change the current date.

    I have tried a lot of things and then came across regex so if some one can help me out or give me a direction to move then I will be very greatfull.

Thanks in advance

$str = file_get_contents('http://www.health.gov.on.ca/english/providers/program/ohip/sob/schedule_master.html');
preg_match('#effective[^\.]*#', $str, $match);
echo $match[0];

 

This is a bare bones method that basicaly gets the file contents from the url listed in the $str variable and seeks out from the word 'effective' and stops when it hits a period. So the result would be:

 

effective June 5, 2008

 

If you don't want the 'effective' part, you can simply use a positive look behind assertion:

 

$str = file_get_contents('http://www.health.gov.on.ca/english/providers/program/ohip/sob/schedule_master.html');
preg_match('#(?<=effective)[^\.]*#', $str, $match);
echo $match[0];

 

The result will be:

 

June 5, 2008

 

Is this what you seek?

 

Cheers,

 

NRG

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.