Jump to content

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.
Link to comment
https://forums.phpfreaks.com/topic/21390-using-output-from-other-sites/
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
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
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.
[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.
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 :)
[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 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
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.
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
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.