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

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

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-08 17:27:46
Original
1087 people have browsed it
<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/
 */
 
 ?>

Related labels:
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template