我的服务器现在在php 5.3上运行,我需要将此调用替换为ereg:
if (ereg("/$", $pref) === FALSE)
{
$pref .= '/';
}
我试过这个,除其他事外没有任何成功:
if (preg_match('~/$~', $pref) === FALSE)
这导致http://example.com/index.phpwww/browse 如果它有任何区别,这是我继承的CodeIgniter 1.6.1应用程序。
我试过了:
if (ereg("/$", $pref) === 0)
正如@PeterM建议的那样,现在转到http://example.com会将我带到http://example.com/index.php/www/browse,但这会给我一条消息:“您提交的URI已禁止使用字符”。这是一个有效的CodeIgniter URL吗?也许我在代码中的其他地方弄乱了什么?
我将codeigniter / application / config / config.php的第126行更改为:
$config['permitted_uri_chars'] = 'a-z 0-9~%.:_\-';
我仍然收到消息。
答案 0 :(得分:3)
将其与0
进行比较,而不是false
。 preg_match
返回匹配数。它仅在出错时返回false
。
答案 1 :(得分:2)
if(substr($pref, -1) !== '/'){
}
OR:
if($pref[strlen($pref)-1] !== '/' ){
//not found
}