# 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>

结果:

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容