检查字符串中是否有带有“通配符”的子字符串
是否可以检查字符串中是否有子字符串加通配符?
我正在检查 url 中的子字符串,我知道有 substring 函数,但我想知道是否可以使用 * 字符?以下是到目前为止我的功能。
function press_getUrl(){
$valid = true;
$current_url = $_SERVER['REQUEST_URI'];
//This is where I am checking for a substring plus whatever is after.
if ($current_url == "/search/node/*"){$valid = false;}
return $valid;
}
$pressValid = press_getUrl();
Is it possible to check a string for a substring plus a wild character?
I am checking a url for a substring and I know there is the substring function but I am wondering if you can use the * character? Below is my function so far.
function press_getUrl(){
$valid = true;
$current_url = $_SERVER['REQUEST_URI'];
//This is where I am checking for a substring plus whatever is after.
if ($current_url == "/search/node/*"){$valid = false;}
return $valid;
}
$pressValid = press_getUrl();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
子字符串不需要通配符。
但是,我认为这样的功能根本没有用处。你想得到什么?
如果它至少被调用
然后被调用,
这对我来说是有意义的,但我不确定这个函数的用途。
还有名字上的注释。你的函数不返回任何网址。所以,不要在其名称中使用“get”。
并且不要混合命名约定。
You don't need no wild characters for substring.
However, I see no use for such a function at all. what you're trying to get?
It would make sense for me if it was at least
and then called
but I am not sure of the use of this function.
also a note on the name. your function return no urls. so, don't use "get" in it's name.
and don't mix naming conventions.
此代码检查字符串是否以
/search/node/
开头:This code checks if string starts with
/search/node/
:不,你不能。对于该示例,请使用
strpos()
或类似方法。如果你想做更复杂的匹配(字符串中间的通配符等),你可以使用正则表达式。
No, you cannot. Use
strpos()
or similar for that example.If you want to do more complex matching (wildcards in the middle of strings, et cetera), you can use regular expressions.
你只需搜索 /search/node 的位置,如果position != 0,则此语句失败
You just search for position of /search/node, if position != 0, this statements fails