考虑:
$a = 'How are you?';
if ($a contains 'are')
echo 'true';
Run Code Online (Sandbox Code Playgroud)
假设我有上面的代码,编写语句的正确方法是什么if ($a contains 'are')?
可能重复:
如何使用PHP检查另一个字符串中是否包含单词?
检查字符串是否包含"."的最有效方法是什么.或不?
我知道你可以用许多不同的方式做到这一点,比如使用正则表达式或循环遍历字符串,看它是否包含一个点(".").
我有以下网址结构.
example.com/items/something_something.
Run Code Online (Sandbox Code Playgroud)
什么是PHP代码来检查该网址包含单词"items"然后显示某些div?
<?php if () { ?> <!--Check if url contains the word "items" -->
Show this
<?php } else { ?>
Don't show this
<?php } ?>
Run Code Online (Sandbox Code Playgroud)
谢谢
我具有以下功能来
在句子中做"exact match"模式($searchPat)($sourceStr)
function isUsed($sourceStr, $searchPat) {
if (strpos($sourceStr, $searchPat) !== false) {
return true;
} else {
return false;
}
}
Run Code Online (Sandbox Code Playgroud)
但是,这并不完全匹配。我按如下方式更改了功能,但这甚至没有执行。
function isUsed($sourceStr, $searchPat) {
if (preg_match("~\b[$sourceStr]\b~", $searchPat)) {
return true;
} else {
return false;
}
}
Run Code Online (Sandbox Code Playgroud)
请问我该怎么做?
我想知道如果该 ip 地址具有 x 字符串,我如何检查我的字符串(特别是一个 ip 地址)
例如
$ip = "66.124.61.23" // ip of the current user
$x = "66.124" // this is the string what I want to check in my $ip.
Run Code Online (Sandbox Code Playgroud)
那么如何检查 $ip 如果它有 $x 的字符串呢?
如果您很难理解这种情况,请发表评论。
谢谢你。