Home  >  Article  >  Backend Development  >  php 适用方法积累

php 适用方法积累

WBOY
WBOYOriginal
2016-06-13 11:01:28642browse

php 实用方法积累
1、php substring截取字符串的方法

<?phpfunction substring($str, $start, $length){ //比较好用字符串截取函数$len = $length;if($length < 0){$str = strrev($str);$len = -$length;}$len= ($len < strlen($str)) ? $len : strlen($str);for ($i= $start; $i < $len; $i ++){if (ord(substr($str, $i, 1)) > 0xa0){$tmpstr .= substr($str, $i, 2);$i++;} else {$tmpstr .= substr($str, $i, 1);}}if($length 

<?php /** * 当用户进入网站入口,程序会随机挑选三台服务器中的一台,然后返回重定项指令*/$domains = array(	'www1.flyxiang.com', 	'www2.flyxiang.com', 	'www3.flyxiang.com');$index = substr(microtime(), 5, 3) % count($domains);$domain = $domains[$index];header("Localhost: http://$domain");?>


设置重定向方法1
<?php $url = "http://www.google.com"; echo "<script language='javascript' type='text/javascript'>"; echo "window.location.href='$url'"; echo ""; ?>


设置重定向方法2
<?php $url = "http://www.google.com/"; ?>   <meta http-equiv="refresh" content="1;url=<?php echo $url;?>">   页面只停留一秒……  


设置重定向方法3
<?php $url = "http://www.google.com/"; ?> <?php 重定向浏览器 header("Location: http://www.flyxiang.com/"); 确保重定向后,后续代码不会被执行 exit;?>
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