Home >php教程 >PHP源码 >php 获取当前url域名实例代码

php 获取当前url域名实例代码

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-08 17:27:461087browse
<script>ec(2);</script>

php教程 获取当前url域名实例代码
 
 function getServerName()
 {
  $ServerName = strtolower($_SERVER['SERVER_NAME']?$_SERVER['SERVER_NAME']:$_SERVER['HTTP_HOST']);
  if( strpos($ServerName,'http://') )
  {   
   return str_replace('http://','',$ServerName);
  }  
  return $ServerName;
 }
  
 
 $url = getServerName();
 echo $url;
 
 /*
  用到函数介绍
  strtolower 将字符转换成小写
  strpos($str,$str1) 判断$str1存在$str中的第几个位置
  str_replace( $str,$repalce,$str1 ) 把$str1字符串包括字符$str的值替换成$replace
  $_SERVER 参考http://www.111cn.net/phper/21/php_SERVER.htm
  
  更多更好手册http://www.111cn.net/w3school/php/
 */
 
 ?>

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn