改变Typo3中的标题标签

时间:2013-04-04 12:16:47

标签: php web

我想在PHP中更改ereg方法。

我试图在没有succsess的情况下使用preg_match

任何人都可以请我改变这段代码:

if (ereg("/$", $pref) === FALSE) {
    $pref .= '/';
}

由于

2 个答案:

答案 0 :(得分:0)

为此,您可以使用strpos

if(strpos($pred, "/") !== false) {
   echo "true";
}

它更快一些,因为你不需要正则表达式和FSM-Mashine。

答案 1 :(得分:0)

您的代码段会检查字符串$pref是否以斜杠结尾。您可以使用substr()

轻松检查相同内容
if (substr($pref, -1) != '/') {
    $pref .= '/';
}

甚至更短:

$pref .= (substr($pref, -1) != '/' ? '/' : '');