溫馨提示×

php stripos如何查找子字符串

PHP
小樊
87
2024-11-16 19:46:47
欄目: 編程語言

stripos 是 PHP 中的一個字符串函數,用于查找一個字符串中首次出現另一個字符串的位置

<?php
$haystack = "Hello, welcome to the world of PHP!";
$needle = "PHP";

$position = stripos($haystack, $needle);

if ($position !== false) {
    echo "子字符串 '{$needle}' 在主字符串 '{$haystack}' 中的位置是: " . $position;
} else {
    echo "子字符串 '{$needle}' 未在主字符串 '{$haystack}' 中找到.";
}
?>

在這個示例中,我們查找子字符串 “PHP” 在主字符串 “Hello, welcome to the world of PHP!” 中的位置。stripos 函數返回子字符串首次出現的位置(從 0 開始計數)。如果子字符串不存在于主字符串中,則返回 false。

0
亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女