Jump to content

Why is nothing displaying


sphinx

Recommended Posts

I'm trying to grab something on a different page with the layout:

 

0 day, 10 hours, 35 min, 59 sec

 

My code to display this information on another page is:

 

<?php
$page_contents = file_get_contents("http://www.mysite.com");
$matches = array();
preg_match('/([0-9,]+) day, ([0-9,]+) hours, ([0-9,]+) min, ([0-9,]+) sec /', $page_contents, $matches);
echo $matches[0];
?>

 

Why is it displaying nothing?

Link to comment
Share on other sites

try this for your preg_match

 

preg_match('/([0-9]+) day, ([0-9]+) hours, ([0-9]+) min, ([0-9]+) sec/', $page_contents, $matches);

 

Fab, worked, thanks!

 

What is "my site"?

At least give us the text it should match.

Btw it will just match the last one.

And, it's not an array but a variable.

Use preg_match_all instead

and print_r it, and you should see what to do with it.

 

Would this be better (Why!)?

 

I'm very novice guys, thanks for the support!

 

How do i insert this seperate from the php code, would i just seperate "echo $matches[0];"? Because i'm looking to fiddle around with the font.

 

Regards

Link to comment
Share on other sites

try this for your preg_match

 

preg_match('/([0-9]+) day, ([0-9]+) hours, ([0-9]+) min, ([0-9]+) sec/', $page_contents, $matches);

 

Fab, worked, thanks!

 

What is "my site"?

At least give us the text it should match.

Btw it will just match the last one.

And, it's not an array but a variable.

Use preg_match_all instead

and print_r it, and you should see what to do with it.

 

Would this be better (Why!)?

 

I'm very novice guys, thanks for the support!

 

How do i insert this seperate from the php code, would i just seperate "echo $matches[0];"? Because i'm looking to fiddle around with the font.

 

Regards

 

Yeh, you need to output the array to screen so you can see what you're working with, then echo whatever array element(s) you need.

 

print_r() will do the trick, but also var_dump() which is more useful.

 

preg_match_all() will match more than one set of day,hours,min,sec strings if it exists.

Link to comment
Share on other sites

Where is this data coming from? Yeh, ajax is what you would use. But, I'd be careful. If this data is coming from an external site or not contained within a variable, then you'd be wasting a ton of resources obtaining every second.

 

Are you just trying to output a time in that format based on a certain timezone or something? What are you trying to do? Maybe there is a better way..

Link to comment
Share on other sites

What about writing a count down "clock" in javascript?

Maybe it can be updated now and then in case of small freezes or whatever, ofc then either by a timed refresh or ajax.

 

oh and sorry about earlier, I'm a bit tired, should have checked if it actually returned an array or a variable. :o Was just logic that it returned a variable instead.

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.