Tandem Posted September 20, 2006 Share Posted September 20, 2006 The site below contains just some plain text.https://daopay.com/svc/numgen?appcode=41970&orderno=yes&format=hash&country=GB&price=1.0I want to be able to take the digits next to "number=" and next to "orderno=" and be able to use them in a script.As of now i have not even attempted this as i really don't know where to start, and would be grateful for any help, thanks. Quote Link to comment https://forums.phpfreaks.com/topic/21390-using-output-from-other-sites/ Share on other sites More sharing options...
HuggieBear Posted September 20, 2006 Share Posted September 20, 2006 You can use [url=http://www.php.net/manual/en/function.file-get-contents.php]file_get_contents()[/url] with the URL (depending on your server setup) to put the entire contents of that file in a string, then use a regular expression to get the two values.RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/21390-using-output-from-other-sites/#findComment-95219 Share on other sites More sharing options...
HuggieBear Posted September 20, 2006 Share Posted September 20, 2006 I've tried the following code and it appears to work fine.[code]<?php$string = file_get_contents('https://daopay.com/svc/numgen?appcode=41970&orderno=yes&format=hash&country=GB&price=1.0');// strip out the new lines$string = preg_replace("/\n/", "", $string);// match the values after the string 'number' and 'orderno'preg_match("/number=(\d+).*orderno=(\d+)/", $string, $matches);foreach ($matches as $k => $v){ if ($k > 0){ echo "Key: $k - Value: $v<br>\n"; }}// of if you don't want to loop$number = $matches[1];$orderno = $matches[2];echo "$number<br>\n$orderno";?>[/code]RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/21390-using-output-from-other-sites/#findComment-95251 Share on other sites More sharing options...
Tandem Posted September 20, 2006 Author Share Posted September 20, 2006 Thanks for your responses. I tried the code out, and i get the following error:Warning: file_get_contents(https://daopay.com/svc/numgen?appcode=41970&orderno=yes&format=hash&country=GB&price=1.0) [function.file-get-contents]: failed to open stream: Invalid argument in C:\...... on line 2Can't figure out why myself as i don't really understand file_get_contents() very well. Quote Link to comment https://forums.phpfreaks.com/topic/21390-using-output-from-other-sites/#findComment-95275 Share on other sites More sharing options...
HuggieBear Posted September 20, 2006 Share Posted September 20, 2006 Can you post the code you have then.RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/21390-using-output-from-other-sites/#findComment-95282 Share on other sites More sharing options...
Tandem Posted September 20, 2006 Author Share Posted September 20, 2006 It's the exact code above, totally on it's own. Quote Link to comment https://forums.phpfreaks.com/topic/21390-using-output-from-other-sites/#findComment-95374 Share on other sites More sharing options...
HuggieBear Posted September 20, 2006 Share Posted September 20, 2006 OK, what version of PHP are you running?RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/21390-using-output-from-other-sites/#findComment-95385 Share on other sites More sharing options...
Tandem Posted September 20, 2006 Author Share Posted September 20, 2006 it's version 4.3.11 Quote Link to comment https://forums.phpfreaks.com/topic/21390-using-output-from-other-sites/#findComment-95426 Share on other sites More sharing options...
Daniel0 Posted September 20, 2006 Share Posted September 20, 2006 [code]<?php$lines = file("https://daopay.com/svc/numgen?appcode=41970&orderno=yes&format=hash&country=GB&price=1.0");$data = array();foreach($lines as $line){ list($key,$value) = explode('=',$line); $data[$key] = $value;}?>[/code]Will read the data into an array.Simpler and it worked when I tested it. Quote Link to comment https://forums.phpfreaks.com/topic/21390-using-output-from-other-sites/#findComment-95430 Share on other sites More sharing options...
Orio Posted September 20, 2006 Share Posted September 20, 2006 Make a file that contains:[code]<?phpphpinfo();?>[/code]Upload it and run it. Then check if the directive "allow_url_fopen" is set to on or off.Orio. Quote Link to comment https://forums.phpfreaks.com/topic/21390-using-output-from-other-sites/#findComment-95433 Share on other sites More sharing options...
HuggieBear Posted September 20, 2006 Share Posted September 20, 2006 Daniel, file() is identical to file_get_contents, the only subtle difference is it returns it into a string instead of an array, it's likely to cause the exact same error.Tandem, create a file like this:phpinfo.php[code=php:0]<?php phpinfo();?>[/code]Open it in your browser and scroll down to PHP Core. Look for the value allow_url_fopen and see if it's switched 'on'RegardsHuggie[size=8pt][color=red][b]Edit:[/b][/color][/size] Damn you Orio :) Quote Link to comment https://forums.phpfreaks.com/topic/21390-using-output-from-other-sites/#findComment-95434 Share on other sites More sharing options...
Tandem Posted September 20, 2006 Author Share Posted September 20, 2006 Oh wait, they weren't working on my local test server, but when i uploaded them to my real host they worked fine.I'll do the allow_url_fopen thing for my test server. Thanks alot for the help. Quote Link to comment https://forums.phpfreaks.com/topic/21390-using-output-from-other-sites/#findComment-95436 Share on other sites More sharing options...
Daniel0 Posted September 20, 2006 Share Posted September 20, 2006 [quote author=HuggieBear link=topic=108764.msg438070#msg438070 date=1158767320]Daniel, file() is identical to file_get_contents, the only subtle difference is it returns it into a string instead of an array, it's likely to cause the exact same error.[/quote]Yeah, but it's simpler and more more effecient to run through a loop and explode the lines instead of using regular expressions. Quote Link to comment https://forums.phpfreaks.com/topic/21390-using-output-from-other-sites/#findComment-95438 Share on other sites More sharing options...
HuggieBear Posted September 20, 2006 Share Posted September 20, 2006 [quote author=Daniel0]Yeah, but it's simpler and more more effecient to run through a loop and explode the lines instead of using regular expressions.[/quote]That I won't deny :) but that still wouldn't have fixed his immediate problem.RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/21390-using-output-from-other-sites/#findComment-95447 Share on other sites More sharing options...
Tandem Posted September 20, 2006 Author Share Posted September 20, 2006 On my test server where the file() and file_get_contents function won't work, the allow_url_fopen is set to On.Should that be set to off or...? Quote Link to comment https://forums.phpfreaks.com/topic/21390-using-output-from-other-sites/#findComment-95459 Share on other sites More sharing options...
Orio Posted September 20, 2006 Share Posted September 20, 2006 If it's on they [i]should[/i] work. Unless something else is blocking it...Is this the FULL error you get?[quote]Warning: file_get_contents(https://daopay.com/svc/numgen?appcode=41970&orderno=yes&format=hash&country=GB&price=1.0) [function.file-get-contents]: failed to open stream: Invalid argument in C:\...... on line 2[/quote]Orio. Quote Link to comment https://forums.phpfreaks.com/topic/21390-using-output-from-other-sites/#findComment-95467 Share on other sites More sharing options...
HuggieBear Posted September 20, 2006 Share Posted September 20, 2006 It should be set to 'on' to allow the functionality you're after, but I think your local test server needs to be set-up to be publically available to use the features properly, in a DMZ otherwise you'll have firewall and all sorts to overcome.I'd be willing to bet it's network related and not php related.RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/21390-using-output-from-other-sites/#findComment-95470 Share on other sites More sharing options...
Daniel0 Posted September 20, 2006 Share Posted September 20, 2006 I am not sure if this could have any effect on it, but is safe mode on? Quote Link to comment https://forums.phpfreaks.com/topic/21390-using-output-from-other-sites/#findComment-95471 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.