Forum Moderators: coopster

Message Too Old, No Replies

Setting a variable from a website

         

henry14

5:24 am on Jan 2, 2008 (gmt 0)

10+ Year Member



Hi,

I am just starting out in PHP and the tutorials I have read seem inappropriate for what I would like to do and I have no idea what to read up on.

I would like to make a script which sets a variable based on a string value in another website.

For example, a website I use states if someone is online/offline in text. I would like to make a script for my site, which can search this website and bring back a value of whether the person is online/offline.

I would just like some advice into what areas I need to learn, or any basic principle on how i would go about doing this.

Thanks alot

henry0

1:44 pm on Jan 2, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Henry14, Welcome to WebmasterWorld!

Most of those script are based on timestamp
and some on cookies
we had a similar question HERE [webmasterworld.com]
If you may start writing something and come back with questions

henry14

1:58 pm on Jan 2, 2008 (gmt 0)

10+ Year Member



thanks alot :)

henry14

3:57 pm on Jan 2, 2008 (gmt 0)

10+ Year Member



I made a short script but it doesn't seem to work..

Could anyone let me know why?

<?php

$url = “http://”;

$page = file_get_contents($url);

echo $page;

$pattern = ‘/ <B CLASS=green>online</B>/’;

preg_match_all($pattern, $file, $results, PREG_PATTERN_ORDER );

echo $results;

?>

Even if I chop the last part off and only echo the $page, it doesn't display the html string from the URL I set.

(I removed the website in "$url = “http://”;" for this example, not in my actual script.

Cheers

henry14

4:53 pm on Jan 2, 2008 (gmt 0)

10+ Year Member



I realized the 's were formatted wrongly, so I can now get echo $page to bring the html in the variable..

Now I get this error:

Warning: preg_match_all() [function.preg-match-all]: Unknown modifier 'B' in C:\wamp\www\mft.php on line 5

I had altered the script slightly:

<?php
$url = 'http://#*$!';
$page = file_get_contents($url);
$pattern = '/<B CLASS=green>online</B>/';
preg_match_all($pattern, $file, $results, PREG_PATTERN_ORDER );
echo $results;
?>

henry14

5:10 pm on Jan 2, 2008 (gmt 0)

10+ Year Member



Euughh sorry to keep posting here.

I managed to get to this:

<?php
$url = 'http://www.example.com/community/?subtopic=characters&name=Tejenuj';
$page = file_get_contents($url);
$pattern = '/<B CLASS=green>(online)<\/B>/';
preg_match_all($pattern, $file, $results, PREG_PATTERN_ORDER);
$online = $results[0][1];
echo $online;
?>

But it doesn't print out the value of $online, which should be a string "online".

[edited by: coopster at 5:14 pm (utc) on Jan. 2, 2008]
[edit reason] generalized domain [/edit]

coopster

5:17 pm on Jan 2, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Seems you may be using the wrong variable ...

preg_match_all($pattern, $page, $results, PREG_PATTERN_ORDER);

piznac

10:10 pm on Jan 2, 2008 (gmt 0)

10+ Year Member



I would also suggest using curl to do this,...