ThinkPHP中的redirect函数&&PHP中的跳转

function redirect($url, $time=0, $msg='') {
//多行URL地址支持把其中的\n,\r删掉
$url = str_replace(array("\n", "\r"), '', $url);
if (empty($msg))
$msg = "系统将在{$time}秒之后自动跳转到{$url}!";
if (!headers_sent()) {
// redirect
if (0 === $time) {
header("Location: " . $url);
} else {
header("refresh:{$time};url={$url}");
echo($msg);
}
exit();
} else {
$str = "<meta http-equiv='Refresh' content='{$time};URL={$url}'>";
if ($time != 0)
$str .= $msg;
exit($str);
}
}


str_replace函数:

mixed str_replace ( mixed $search , mixed $replace , mixed $subject [, int &$count ] )


If search and replace are arrays, then str_replace() takes a value from each array and uses them to do search and replace on subject . If replace has fewer values than search , then an empty string is used for the rest of replacement values. If search is an array and replace is a string, then this replacement string is used for every value of search . The converse would not make sense, though.


If search or replace are arrays, their elements are processed first to last.

(如果参数search和replace都是数组,那么str_replace()将对search和replace中的值一一对应进行对subject的替换。如果replace数组中值的个数比search少,那么剩余的值会默认为空值。(PS:如果replace数组中的值的个数比search多,多余的将被忽略。)

如果search是数组而且replace是一个字符串(String),那么替换的String将被用来进行search中所有的值的替换。尽管反过来是不行的。

如果search或者replace是数组,他们的值都是从头到尾的进行对应替换)

如果 HTTP 标头尚未被发送出去的话,headers_sent() 将返回 FALSE,否则返回 TRUE,通过header发送,否则通过meta标签跳转。

PHP中的跳转:(来自百度文库,有改动)

1、header()函数是PHP中进行页面跳转的一种十分简单的方法。header()函数的主要功能是将HTTP协议标头(header)输出到浏览器。

     <?php

header("Location: http://www.baidu.com");

exit;//确保重定向后,后面的代码不会被执行

?>


2、Meta标签

meta标签是HTML中负责提供文档元信息的标签,在PHP程序中使用该标签,也可以实现页面的跳转。弱定义http_equiv为fresh,则打开面的时候将根据content规定的值在一定时间内跳转到相应页面。

<meta http-equiv="refesh" content="秒数";url=http://www.baidu.com>


3、javascipt实现跳转

 window.location.href=http://www.baidu.com;
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值