kejo Posted January 29, 2008 Share Posted January 29, 2008 hello hope you can help me. i want to get a value from a page (that doesnt belong to me) and use that value on my script. how can i do this? for example, i want to show on my page the number of "firefox downloads", that you read in this page on the right: http://www.spreadfirefox.com/ can anyone help ? i don't know what method to use. Quote Link to comment https://forums.phpfreaks.com/topic/88430-how-to-get-a-valuestring-from-an-external-page/ Share on other sites More sharing options...
sasa Posted January 29, 2008 Share Posted January 29, 2008 try <?php $a = file_get_contents('http://www.spreadfirefox.com/'); preg_match('/<span id="download-count"[^>]*>[^0-9]*([0-9]+)/',$a,$b); echo $b[1]; ?> Quote Link to comment https://forums.phpfreaks.com/topic/88430-how-to-get-a-valuestring-from-an-external-page/#findComment-452585 Share on other sites More sharing options...
kejo Posted January 29, 2008 Author Share Posted January 29, 2008 thanks mate you rock! ill let you know if that works Quote Link to comment https://forums.phpfreaks.com/topic/88430-how-to-get-a-valuestring-from-an-external-page/#findComment-452592 Share on other sites More sharing options...
kejo Posted January 29, 2008 Author Share Posted January 29, 2008 sasa how come the script you wrote takes time to load? other pages are faster than this one. is there a faster method? thanks Quote Link to comment https://forums.phpfreaks.com/topic/88430-how-to-get-a-valuestring-from-an-external-page/#findComment-452758 Share on other sites More sharing options...
effigy Posted January 29, 2008 Share Posted January 29, 2008 It loads OK for me. It takes time because you're accessing an external site. Quote Link to comment https://forums.phpfreaks.com/topic/88430-how-to-get-a-valuestring-from-an-external-page/#findComment-452771 Share on other sites More sharing options...
kejo Posted January 29, 2008 Author Share Posted January 29, 2008 thank you so much. i love this forum. really helpful. anyway im trying to understand what this string means: ('/<span id="download-count"[^>]*>[^0-9]*([0-9]+)/' i dont know the regex :\ so now that im "adapting " your script to my personal needs, i have to edit it (the actual url is not the one i posted) Quote Link to comment https://forums.phpfreaks.com/topic/88430-how-to-get-a-valuestring-from-an-external-page/#findComment-452780 Share on other sites More sharing options...
effigy Posted January 29, 2008 Share Posted January 29, 2008 See the Regular Expression resources here. Quote Link to comment https://forums.phpfreaks.com/topic/88430-how-to-get-a-valuestring-from-an-external-page/#findComment-452789 Share on other sites More sharing options...
cooldude832 Posted January 29, 2008 Share Posted January 29, 2008 If it doesn't belong to you, you shouldn't take it without asking first! Quote Link to comment https://forums.phpfreaks.com/topic/88430-how-to-get-a-valuestring-from-an-external-page/#findComment-452794 Share on other sites More sharing options...
kratsg Posted January 29, 2008 Share Posted January 29, 2008 sasa how come the script you wrote takes time to load? other pages are faster than this one. is there a faster method? thanks You can always use a method of cacheing the number every day so while it may not be as UP TO DATE on a second-by-second basis, it'll be reasonably close. By this, I mean calling the page, saving the number in a flat file on your server that you can access readily and display the number. Quote Link to comment https://forums.phpfreaks.com/topic/88430-how-to-get-a-valuestring-from-an-external-page/#findComment-452806 Share on other sites More sharing options...
kejo Posted January 29, 2008 Author Share Posted January 29, 2008 ok thanks im learning much more thanks to you guys. anyway im still trying to understand the regex. [^>] = looks for all text except the < [^0-9] = looks for all non numeric characters *([0-9]+) = ??? what about the last? thanks mates you rock! Quote Link to comment https://forums.phpfreaks.com/topic/88430-how-to-get-a-valuestring-from-an-external-page/#findComment-452811 Share on other sites More sharing options...
kratsg Posted January 29, 2008 Share Posted January 29, 2008 ok thanks im learning much more thanks to you guys. anyway im still trying to understand the regex. [^>] = looks for all text except the < [^0-9] = looks for all non numeric characters *([0-9]+) = ??? what about the last? thanks mates you rock! ('/<span id="download-count"[^>]*>[^0-9]*([0-9]+)/' Ok, you are right about the first two.. Except it looks like this: [^>]* > [^0-9]* ([0-9]+) If you broke it into separate entities. It goes through the string until it hits a ">" hence the looks for all text except the >. Then, it reads off the ">", goes through all NON-NUMERIC stuff until it hits the numbers. Then, it saves (or "remembers") at least one or more numbers from this point. a * after the set means 0 or more times. a + after the set means 1 or more times. Check this link for quick references if you need help :-) http://www.quanetic.com/regex.php Quote Link to comment https://forums.phpfreaks.com/topic/88430-how-to-get-a-valuestring-from-an-external-page/#findComment-452824 Share on other sites More sharing options...
effigy Posted January 29, 2008 Share Posted January 29, 2008 [^>] = looks for all text except the < [^0-9] = looks for all non numeric characters *([0-9]+) = ??? what about the last? The first is correct, except it's >. The second is incorrect because you're not pairing the quantifier. Quantifiers determine how much of something is matched, and always follow what they affect. Therefore, the second part is [^0-9]*, which matches anything that is not a digit zero or more times. The third part, without the leading quantifier, captures any digits that appear one or more times. Quote Link to comment https://forums.phpfreaks.com/topic/88430-how-to-get-a-valuestring-from-an-external-page/#findComment-452826 Share on other sites More sharing options...
kejo Posted January 29, 2008 Author Share Posted January 29, 2008 you are simply amazing effigy + kratsg + sasa ! Quote Link to comment https://forums.phpfreaks.com/topic/88430-how-to-get-a-valuestring-from-an-external-page/#findComment-452834 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.