温馨提示×

stripos php 在哪里使用

PHP
小樊
95
2024-11-28 18:46:13
栏目: 编程语言

stripos() 是 PHP 中的一个字符串函数,它用于在字符串中查找一个子字符串,并返回其第一次出现的位置

<?php $haystack = 'Hello, welcome to the world of PHP!'; $needle = 'PHP'; $position = stripos($haystack, $needle); if ($position !== false) { echo "The substring '{$needle}' is found at position {$position} in the string '{$haystack}'."; } else { echo "The substring '{$needle}' is not found in the string '{$haystack}'."; } ?> 

在这个示例中,我们在字符串 $haystack 中查找子字符串 $needle(即 ‘PHP’)。stripos() 函数返回子字符串在源字符串中第一次出现的位置(从 0 开始计数)。如果子字符串不存在于源字符串中,则返回 false

0