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? Link to comment https://forums.phpfreaks.com/topic/221342-why-is-nothing-displaying/ 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. Link to comment https://forums.phpfreaks.com/topic/221342-why-is-nothing-displaying/#findComment-1145888 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); Link to comment https://forums.phpfreaks.com/topic/221342-why-is-nothing-displaying/#findComment-1145889 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 Link to comment https://forums.phpfreaks.com/topic/221342-why-is-nothing-displaying/#findComment-1145890 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. Link to comment https://forums.phpfreaks.com/topic/221342-why-is-nothing-displaying/#findComment-1145892 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/ Link to comment https://forums.phpfreaks.com/topic/221342-why-is-nothing-displaying/#findComment-1145893 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? Link to comment https://forums.phpfreaks.com/topic/221342-why-is-nothing-displaying/#findComment-1145895 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.. Link to comment https://forums.phpfreaks.com/topic/221342-why-is-nothing-displaying/#findComment-1145946 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. Link to comment https://forums.phpfreaks.com/topic/221342-why-is-nothing-displaying/#findComment-1145991 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.