>  기사  >  백엔드 개발  >  php 适用方法积累

php 适用方法积累

WBOY
WBOY원래의
2016-06-13 11:01:28669검색

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;?>
성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.