Home > Backend Development > PHP Tutorial > php 适用方法积累

php 适用方法积累

WBOY
Release: 2016-06-13 11:01:28
Original
725 people have browsed it

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 
Copy after login

<?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");?>
Copy after login


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


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


设置重定向方法3
<?php $url = "http://www.google.com/"; ?> <?php 重定向浏览器 header("Location: http://www.flyxiang.com/"); 确保重定向后,后续代码不会被执行 exit;?>
Copy after login
Related labels:
source:php.cn
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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template