Jump to content

Using output from other sites?


Tandem

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
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
Link to comment
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.
Link to comment
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.
Link to comment
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 :)
Link to comment
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.
Link to comment
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.
Link to comment
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
Link to comment
Share on other sites

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.