我想在PHP中更改ereg方法。
我试图在没有succsess的情况下使用preg_match
。
任何人都可以请我改变这段代码:
if (ereg("/$", $pref) === FALSE) {
$pref .= '/';
}
由于
答案 0 :(得分:0)
答案 1 :(得分:0)
您的代码段会检查字符串$pref
是否以斜杠结尾。您可以使用substr()
:
if (substr($pref, -1) != '/') {
$pref .= '/';
}
甚至更短:
$pref .= (substr($pref, -1) != '/' ? '/' : '');