Jump to content

Archived

This topic is now archived and is closed to further replies.

Tandem

Using output from other sites?

Recommended Posts

The site below contains just some plain text.

https://daopay.com/svc/numgen?appcode=41970&orderno=yes&format=hash&country=GB&price=1.0

I 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.

Share this post


Link to post
Share on other sites
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.

Regards
Huggie

Share this post


Link to post
Share on other sites
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]

Regards
Huggie

Share this post


Link to post
Share on other sites
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 2

Can't figure out why myself as i don't really understand file_get_contents() very well.

Share this post


Link to post
Share on other sites
[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.

Share this post


Link to post
Share on other sites
Make a file that contains:
[code]<?php
phpinfo();
?>[/code]

Upload it and run it. Then check if the directive "allow_url_fopen" is set to on or off.

Orio.

Share this post


Link to post
Share on other sites
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'

Regards
Huggie

[size=8pt][color=red][b]Edit:[/b][/color][/size] Damn you Orio :)

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
[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.

Share this post


Link to post
Share on other sites
[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.

Regards
Huggie

Share this post


Link to post
Share on other sites
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...?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Regards
Huggie

Share this post


Link to post
Share on other sites

×

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.