Hongmu Notes
Home Language Notes PHP checks whether a specified string exists.
Language Notes PHP

PHP checks whether a specified string exists.

PHP checks whether a specified string exists.

In PHP, you can use built-in string functions. strpos() Check whether a specified string exists within another string.

Below is how to use it. strpos() Example code for checking whether a specified string exists:

 隐藏内容:评论后查看
$myString = "This is a sample string";
$findString = "sample";

if (strpos($myString, $findString) !== false) {
echo "The string '$findString' was found in the string '$myString'.";
} else {
echo "The string '$findString' was not found in the string '$myString'.";
}

In this example,strpos() The function accepts two parameters: the first is the string to be checked, and the second is the string to be searched for. If the specified string is found, the function returns the index of its first occurrence; if the specified string is not found, it returns `false`. Therefore, we use the `!==` operator to ensure that the returned position index is not equal to `false`.

if $findString Exists $myString In this case, the output will be "The string 'sample' was found in the string 'This is a sample string'." Otherwise, the output will be "The string 'sample' was not found in the string 'This is a sample string'."

微信赞赏

WeChat

支付宝赞赏

Alipay

✍️ Author: Hong Mu

webmaster · Thanks for reading, stay tuned for more exciting content

Author homepage View home page →

Related articles

PHP ob function record

PHP ob function record Language Notes PHP

Usage of the following three functions ob_get_contents(); ob_end_clean(); ob_start(); You can use these functions to buffer local files and execute local script code. Use ob_start() to save the output code into the buffer, and the page will not be displayed; then use ob_get_contents to get the data in the buffer. o…
👁 140
PHP preg

PHP preg Language Notes PHP

The preg_match_all function is used to perform a global regular expression match. preg_match_all() Syntax int preg_match_all ( string $pattern , string $subject [, array &$matches [, int $flags = PREG…
👁 169
Detailed explanation of PHP ternary operator and if

Detailed explanation of PHP ternary operator and if Language Notes PHP

Ternary operator condition ? Result 1 : Result 2 Explanation: The position in front of the question mark is the condition for judgment. If the condition is met, the result is 1, and if it is not met, the result is 2. This article compares and explains the ternary operator and if...else... in detail. I hope it will be helpful to everyone. Today when I was revising my paper online, I encountered a statement that I couldn’t understand: $if_summary = $row['IF_SUMMARY']=…
👁 187
PHP cast type

PHP cast type Language Notes PHP PHP collection PHP and mysql

Get the data type 1. If you want to check the value and type of an expression, use var_dump(). 2. If you just want to get an easy-to-read type expression for debugging, use gettype(). 3. To check a certain type, do not use gettype(), but use the is_type() function. Converting Strings to Numbers When a string is evaluated as a number, the result is determined according to the following rules...
👁 231

Recommended reading

(PC+WAP) Smart Access Control System Website Template – Download Face Recognition Gate Machine Website Source Code – 1127

(PC+WAP) Smart Access Control System Website Template – Download Face Recognition Gate Machine Website Source Code – 1127 Practical Collection pbootcms Template

An intelligent access control system and a PbootCMS website template for facial recognition gates – compatible with both PC and WAP devices. The modern, tech-driven design is ideal for showcasing access control systems, facial recognition devices, and security solutions. It enables smart security companies to showcase their products online and attract property management and commercial clients. Template Display | Installation Instructions | Website Backend: /admin.php | Username: admin | Password: admin | Extraction Password: www.4s...
👁 69
Empire CMS – A dual-end (WAP/PC) adaptive template with traditional Chinese language support and dual-language switching functionality for news and information content – 022

Empire CMS – A dual-end (WAP/PC) adaptive template with traditional Chinese language support and dual-language switching functionality for news and information content – 022 Practical Collection empire template

A news-friendly template – includes fixes for: an unusual background image in the navigation bar; hidden thumbnails; and missing article images; a dual-platform template compatible with both mobile and desktop devices; and the ability to switch between Chinese and Traditional Chinese preview views; Video Preview feature.
👁 265
Responsive children's accessories, clothing and apparel website template – 0973

Responsive children's accessories, clothing and apparel website template – 0973 Practical Collection Yiyou template

This EyouCMS responsive template is ideal for the children's accessories, apparel, and clothing industries. Its stylish and playful design makes it perfect for showcasing children's clothing products, accessory collections, brand identity, and new product launches – helping children's clothing brands attract parents as online customers. Template Demo | Installation Instructions | Website Backend: /login.php | Username: admin | Password: admin | Related Articles: Summary of Common Installation Issues for EyouCMS | EyouCMS...
👁 49
(Adaptive Mobile Version) Responsive News and Information Technology Blog – pbootCMS Template; Game News Website Source Code Download – 0152

(Adaptive Mobile Version) Responsive News and Information Technology Blog – pbootCMS Template; Game News Website Source Code Download – 0152 Practical Collection pbootcms Template

An adaptive, mobile-friendly responsive PbootCMS template for news and technology blogs, ideal for gaming or tech news websites. Its stylish and dynamic design effectively aggregates industry updates and in-depth articles – making it the perfect choice for game enthusiasts or tech bloggers looking to build an information platform and attract like-minded readers. Template Preview | Installation Instructions | Website Backend: /admin.php | Username: admin | Password: admin | Extract...
👁 57
(PC+WAP) Trademark Registration Search Website Template | Patent Application Website Source Code Download – 1128

(PC+WAP) Trademark Registration Search Website Template | Patent Application Website Source Code Download – 1128 Practical Collection pbootcms Template

A PbootCMS website template for trademark registration searches and patent application processes, compatible with both PC and WAP devices. Its professional and sophisticated design makes it ideal for intellectual property agencies to showcase their services and success stories, helping them attract potential clients online. Template Display | Installation Instructions | Website Backend: /admin.php | Username: admin | Password: admin | Extraction Password: www.4s5.cn | Related Articles: P...
👁 42
Responsive children's clothing design website template – 0974

Responsive children's clothing design website template – 0974 Practical Collection Yiyou template

An eYouCMS responsive website template designed for the children's wear and apparel design industry. Its stylish and playful design style is ideal for showcasing children's clothing products, design trends, brand identity, and new product launches. This template helps children's wear brands attract parent customers online and enhance their brand awareness. Template Display | Installation Instructions | Website Backend: /login.php | Username: admin | Password: admin | Related Articles: Summary of Common Installation Issues for eYouCMS...
👁 42