note 72944 added to function.socket-create
| From: | gancheffatgmaildotcom at osu1 dot php dot net | Date: | Mon, 05 Feb 2007 11:14:18 +0000 |
| Subject: | note 72944 added to function.socket-create | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-122878@lists.php.net to get a copy of this message | ||
here's a way to get the currency:
example getCurrency("BGN", "USD");
function getCurrency($from, $to, $cache = true) {
if ($cache && $_SESSION['currency'][$from][$to]['value'] &&
(time() - $_SESSION['currency'][$from][$to]['time']) < 3600)
return $_SESSION['currency'][$from][$to]['value'];
$host = "www.xe.com";
$port = "80";
$data = "Amount=1&From=" . strtoupper($from) . "&To=" .
strtoupper($to);
$header =
"POST /ucc/convert.cgi HTTP/1.1\n" .
"Host: $host:$port\n" .
"Content-Type: application/x-www-form-urlencoded\n" .
"Content-Length: " . strlen($data) . "\n\n" .
$data . "\n";
$s = socket_create(AF_INET, SOCK_STREAM, 0);
$z = socket_connect($s, gethostbyname($host), $port);
socket_write ($s, $header, strlen($header));
while (true) {
$c = @socket_read($s, 1);
if ($c == "\n") {
if (preg_match("/$from = (.+) $to/i", $line, $matches) ||
preg_match("/<\/html>/i", $line)) break;
$line = "";
} else $line .= $c;
}
socket_close($s);
$_SESSION['currency'][$from][$to]['time'] = time();
$_SESSION['currency'][$from][$to]['value'] = str_pad(round($matches[1], 5),
7, "0");
return ($matches[1]) ? str_pad(round($matches[1], 5), 7, "0") : "0.00000";
}
----
Server IP: 195.149.248.161
Probable Submitter: 213.91.245.1 (proxied: unknown)
----
Manual Page -- http://www.php.net/manual/en/function.socket-create.php
Edit -- https://master.php.net/note/edit/72944
Del: integrated -- https://master.php.net/note/delete/72944/integrated
Del: useless -- https://master.php.net/note/delete/72944/useless
Del: bad code -- https://master.php.net/note/delete/72944/bad+code
Del: spam -- https://master.php.net/note/delete/72944/spam
Del: non-english -- https://master.php.net/note/delete/72944/non-english
Del: in docs -- https://master.php.net/note/delete/72944/in+docs
Del: other reasons-- https://master.php.net/note/delete/72944
Reject -- https://master.php.net/note/reject/72944
Search -- https://master.php.net/manage/user-notes.php