Home  >  Article  >  Backend Development  >  How to determine whether a string contains dots in php

How to determine whether a string contains dots in php

青灯夜游
青灯夜游Original
2022-12-15 16:55:454445browse

3 methods: 1. Use stripos(), the syntax is "stripos($str, ".")", and the returned position value is included. 2. Use strripos(), the syntax is "strripos($str, ".")", and the returned position value is included. 3. Use explode() with the syntax "explode($str,".")". If the returned array is an empty array, it will not be included. Otherwise, it will be included.

How to determine whether a string contains dots in php

The operating environment of this tutorial: windows7 system, PHP version 8.1, DELL G3 computer

php detection string Methods to determine whether a string contains specified characters

Method 1: Use the stripos() function to detect

The stripos() function can find a string in another string The position of the first occurrence in a string (case-insensitive).

If the specified character exists, return the position of the first occurrence; if not found, return FALSE.

Note: The string position starts from 0, not from 1.

Example:

";
}else{
	echo $str." 中不包含指定字符 圆点.
"; } ?>

How to determine whether a string contains dots in php

Method 2: Use strripos() function to detect

strripos() function can Finds the last occurrence of a string within another string (case-insensitive).

If the specified character exists, return the position of the last occurrence; if not found, return FALSE.

Example:

";
}else{
	echo $str." 中不包含指定字符 圆点.
"; } ?>

How to determine whether a string contains dots in php

Method 3: Use the explode() function to detect

explode() function usage Specifies the delimiter to split a string and returns an array of strings.

If the array is not an empty array (the array length is greater than 1), it is included; otherwise, the array is empty and does not contain another string

1){
	echo $url." 中包含 圆点".$str;
}else{
	echo $url." 中没有包含圆点 ".$str; 
}
?>

How to determine whether a string contains dots in php

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of How to determine whether a string contains dots in php. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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