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

使用其他Web站点的数据

<html>
  <head>
   <title> Stock Quote From NASDAQ </title>
  </head>
  <body>

<?php
 $symbol = 'AMZN';
 echo "<h1>Stock qupte for ".$symbol."</h1>";

 $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 "<p>".$symbol." was last sold at: ".$quote."</p>";
echo "<p>Quote current as of ".$date." at ".$time."</p>";

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

?>
    
  </body>
</html>

显示结果:

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

查询

<html>
  <head>
   <title> Site submission results </title>
  </head>
  <body>
<h1>Site submission results</h1>
<?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.' <br />';

$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 "<br>All submitted details are ok.<br>";
echo '<br>Thank you for submitting your site.<br>'.
'It will be visited by one of our staff members soon.';


?>
    
  </body>
</html>

结果:

637318-20161017090315107-204954492.png

637318-20161017090322232-179606715.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值