我是PHP正则表达式的新手,我读了http://php.net/manual/en/function.preg-match.php。但找不到修复我的bug的方法。 你能帮我个忙吗? 感谢。
<?php
$myURL = "/something/";
// If myURL include two or more than two '/' then return Found, Else return Not found two '/'
if (preg_match("/\/?\//", $myURL)) {
echo "found";
} else {
echo "not found";
}
?>
答案 0 :(得分:6)
答案 1 :(得分:3)
<?php
$myURL = "/something/";
// If myURL include two or more than two '/' then return Found, Else return Not found two '/'
if (preg_match("/\/.*\//", $myURL)) {
echo "found";
} else {
echo "not found";
}
?>
答案 2 :(得分:0)
如果你想以正则表达式方式去:
$myURL = "/some//thing/";
if (array_search("//", preg_match_all("/\/?\//", $myURL))) {
echo "found";
} else {
echo "not found";
}
?>