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

Link to comment
Share on other sites

$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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.