finding and subtracting a string from within a large string in php

hi.

plainly n simply:

I want to use a php script to issue a wget command in linux to download a page into a string in php.
From this string, I wish to single out a line containing the string "Start time:</td><td>22-Nov-04 20:35:00".

From this string, I wish to find 1) the date and 2) the time that this countdown started.

How?:)

thanks very much

Daryn
darynAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

b_locoCommented:
First of all, you don't need to use wget to download the html of a webpage. you can do it with php only. My example doesn't work with url's that contain query strings. However if you run into any trouble tell me because you can overcome it with curl.

Supposing that after that string there is a "</td>" (could be anything, just replace $end_str with it):

function extract_url($url)
{
   $filename = $url;
   $handle = fopen ($filename, "r");
   $content = fread ($handle, filesize ($filename));
   fclose ($handle);
   
   return $content;
}
$str = extract_url("http://www.example.com/test.htm");
$start_str = "Start time:</td><td>";
$end_str = "</td>";
$begin = str_pos($str, $start_str);
$end = str_pos($str,$end_str, $begin);

$final = substr($str, $begin+strlen($start_str), $end);
$arr = explode(" ",$final);

$date = $arr[0];
$time = $arr[1];
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jmsloanCommented:
If the string stays constant(meaning length size)

you could just use the substr command to get what you want

$mystr = "Start time:</td><td>22-Nov-04 20:35:00";

$date = substr("$mystr", 20, 9);
$time = substr("$mystr", 30, 8);
0
cmaronCommented:
If you wanted to use wget for a particular reason (ie. command-line arguments) you can use PHP's popen function.

For example:
<?PHP

     $f = popen('wget http://www.website.com/file.html','r');
?>

The resource returned by popen works just like the one returned by fopen.

-C
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.