Jump to content


Photo

Using output from other sites?


  • Please log in to reply
17 replies to this topic

#1 Tandem

Tandem
  • Members
  • PipPipPip
  • Advanced Member
  • 251 posts

Posted 20 September 2006 - 11:03 AM

The site below contains just some plain text.

https://daopay.com/s...ry=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.

#2 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 20 September 2006 - 11:15 AM

You can use file_get_contents() 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
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#3 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 20 September 2006 - 12:31 PM

I've tried the following code and it appears to work fine.

<?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";

?>

Regards
Huggie
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#4 Tandem

Tandem
  • Members
  • PipPipPip
  • Advanced Member
  • 251 posts

Posted 20 September 2006 - 01:03 PM

Thanks for your responses. I tried the code out, and i get the following error:

Warning: file_get_contents(https://daopay.com/s...ry=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.

#5 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 20 September 2006 - 01:09 PM

Can you post the code you have then.

Regards
Huggie
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#6 Tandem

Tandem
  • Members
  • PipPipPip
  • Advanced Member
  • 251 posts

Posted 20 September 2006 - 02:46 PM

It's the exact code above, totally on it's own.

#7 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 20 September 2006 - 03:06 PM

OK, what version of PHP are you running?

Regards
Huggie
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#8 Tandem

Tandem
  • Members
  • PipPipPip
  • Advanced Member
  • 251 posts

Posted 20 September 2006 - 03:40 PM

it's version 4.3.11

#9 Daniel0

Daniel0
  • Staff Alumni
  • Advanced Member
  • 11,956 posts

Posted 20 September 2006 - 03:44 PM

<?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;
}
?>

Will read the data into an array.

Simpler and it worked when I tested it.

#10 Orio

Orio
  • Staff Alumni
  • Advanced Member
  • 2,491 posts

Posted 20 September 2006 - 03:47 PM

Make a file that contains:
<?php
phpinfo();
?>

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

Orio.
Think you're smarty?

(Gone until 20 to November)

#11 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 20 September 2006 - 03:48 PM

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
<?php
   phpinfo();
?>


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

Edit: Damn you Orio :)
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#12 Tandem

Tandem
  • Members
  • PipPipPip
  • Advanced Member
  • 251 posts

Posted 20 September 2006 - 03:51 PM

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.

#13 Daniel0

Daniel0
  • Staff Alumni
  • Advanced Member
  • 11,956 posts

Posted 20 September 2006 - 03:53 PM

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.


Yeah, but it's simpler and more more effecient to run through a loop and explode the lines instead of using regular expressions.

#14 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 20 September 2006 - 03:57 PM

Yeah, but it's simpler and more more effecient to run through a loop and explode the lines instead of using regular expressions.


That I won't deny  :)  but that still wouldn't have fixed his immediate problem.

Regards
Huggie
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#15 Tandem

Tandem
  • Members
  • PipPipPip
  • Advanced Member
  • 251 posts

Posted 20 September 2006 - 04:03 PM

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

#16 Orio

Orio
  • Staff Alumni
  • Advanced Member
  • 2,491 posts

Posted 20 September 2006 - 04:05 PM

If it's on they should work. Unless something else is blocking it...

Is this the FULL error you get?

Warning: file_get_contents(https://daopay.com/s...ry=GB&price=1.0) [function.file-get-contents]: failed to open stream: Invalid argument in C:\...... on line 2



Orio.
Think you're smarty?

(Gone until 20 to November)

#17 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 20 September 2006 - 04:07 PM

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
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#18 Daniel0

Daniel0
  • Staff Alumni
  • Advanced Member
  • 11,956 posts

Posted 20 September 2006 - 04:08 PM

I am not sure if this could have any effect on it, but is safe mode on?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users