PHP之使用网络函数和协议函数

使用其他Web站点的数据



Stock Quote From NASDAQ

<?php
\(symbol = 'AMZN'; echo "<h1>Stock qupte for ".\)symbol."";

\(url = 'http://finance.yahoo.com/d/quotes.csv'.'?s='.\)symbol.'&e=.csv&f=fl1d1t1c1ohgv';
if (!(\(contents = file_get_contents(\)url))) {
die('Fail to open '. $url);
}

list($symbol, $quote, $date, $time) = explode(',', $contents);

\(date = trim(\)date, '"');
\(time = trim(\)time, '"');

echo "

".\(symbol." was last sold at: ".\)quote."

";
echo "

Quote current as of ".\(date." at ".\)time."

";

\(baiduURL = "http://baidu.com"; echo "This information retrieved from <br /> "; echo "<p><a href=\"".\)baiduURL."">".$baiduURL."

";

?>


显示结果:

Stock qupte for AMZN

N/A was last sold at: 822.96

Quote current as of 10/14/2016 at 4:00pm

This information retrieved from
http://baidu.com

查询



Site submission results


Site submission results


<?php
$url = $_REQUEST['url'];
$email = $_REQUEST['email'];

\(url_parse = parse_url(\)url);
$host = $url_parse['host'];

if (!\(ip = gethostbyname(\)host)) {
echo 'Host for URL does not have valid IP.';
exit;
}

echo 'Host is at IP '.$ip.'
';

$email = explode('@', $email);
$email_host = $email[1];

if (!dns_get_mx($email_host, $mxhostsarr)) {
echo 'Email address is not at valid host.';
exit;
}

echo 'Email is delivered via: ';
foreach($mxhostsarr as $mx) {
echo $mx.'/';
}

echo "
All submitted details are ok.
";
echo '
Thank you for submitting your site.
'.
'It will be visited by one of our staff members soon.';

?>



结果:

posted @ 2016-10-17 16:36  马在路上  阅读(293)  评论(0)    收藏  举报