sphinx Posted December 11, 2010 Share Posted December 11, 2010 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? Quote Link to comment Share on other sites More sharing options...
MMDE Posted December 11, 2010 Share Posted December 11, 2010 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. Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted December 11, 2010 Share Posted December 11, 2010 try this for your preg_match preg_match('/([0-9]+) day, ([0-9]+) hours, ([0-9]+) min, ([0-9]+) sec/', $page_contents, $matches); Quote Link to comment Share on other sites More sharing options...
sphinx Posted December 11, 2010 Author Share Posted December 11, 2010 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 Quote Link to comment Share on other sites More sharing options...
Anti-Moronic Posted December 11, 2010 Share Posted December 11, 2010 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. Quote Link to comment Share on other sites More sharing options...
sphinx Posted December 11, 2010 Author Share Posted December 11, 2010 this is the output: http://prizelive.net/sm/ Quote Link to comment Share on other sites More sharing options...
sphinx Posted December 11, 2010 Author Share Posted December 11, 2010 Would it be ajax that i'd use to make that constantly update without refreshing page everytime? Quote Link to comment Share on other sites More sharing options...
Anti-Moronic Posted December 12, 2010 Share Posted December 12, 2010 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.. Quote Link to comment Share on other sites More sharing options...
MMDE Posted December 12, 2010 Share Posted December 12, 2010 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. Was just logic that it returned a variable instead. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.