문자열에 단어가 포함되어 있는지 php 확인
$myString = 'Hello Bob how are you?';
if (strpos($myString, 'Bob') !== false) {
echo "My string contains Bob";
}
문자열이 포함 된 경우 php chech
$a = 'How are you?';
if (strpos($a, 'are') !== false) {
echo 'true';
}
문자열이 포함 된 경우 php 찾기
if (strpos($string, 'substring') !== false) {
// do stuff
}
문자열에 php 에 하위 문자열이 포함되어 있는지 확인하는 방법
$a = 'How are you?';
if (strpos($a, 'are') !== false) {
echo 'true';
}
문자열에 특정 단어가 포함되어 있는지 어떻게 확인합니까?
$a = 'Hello world?';
if (strpos($a, 'Hello') !== false) { //PAY ATTENTION TO !==, not !=
echo 'true';
}
if (stripos($a, 'HELLO') !== false) { //Case insensitive
echo 'true';
}
문자열에 문자 php 가 포함되어 있는지 확인하십시오
// this method is new with PHP 8 and above
$haystack = "Damn, I wonder if this string contains a comma.";
if (str_contains($haystack, ",")) {
echo "There is a comma!!";
}