How to determine if a string does not contain a certain character in php

藏色散人
Release: 2023-03-11 12:06:01
Original
3215 people have browsed it

In PHP, you can use the strpos() function to determine that a string does not contain another string. The implementation code is "if (strpos($a, 'are') !== false) {. ..} else {...}".

How to determine if a string does not contain a certain character in php

The operating environment of this article: windows7 system, PHP7.1 version, DELL G3 computer

How does php determine that a string does not contain a certain character? Determine whether a string contains another string?

We can use the strpos() function to determine whether the string contains another string:

$a = 'How are you?';
if (strpos($a, 'are') !== false) {
    echo 'true';
} else {
    echo 'false';
}
Copy after login

Note that you must use !== false to make the judgment conditional statement, strpos( ) If the string is not found, it returns FALSE. If another string is found at the beginning of the string, it returns 0. Other positions are integers greater than 0, so we cannot use code like this!strpos( $a, 'are'), this will lead to misjudgment.

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of How to determine if a string does not contain a certain character in php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template