PHP之mb_stripos使用


mb_stripos

  • (PHP 5 >= 5.2.0, PHP 7)
  • mb_stripos — Finds position of first occurrence of a string within another, case insensitive
  • mb_stripos — 大小寫不敏感地查找字符串在另一個字符串中首次出現的位置

Description

int mb_stripos ( 
    string $haystack , 
    string $needle [, 
    int $offset = 0 [, 
    string $encoding = mb_internal_encoding() ]] 
    )
//mb_stripos() returns the numeric position of the first occurrence of needle in the haystack string. Unlike mb_strpos(), mb_stripos() is case-insensitive. If needle is not found, it returns FALSE.
//mb_stripos() 返回 needle 在字符串 haystack 中首次出現位置的數值。 和 mb_strpos() 不同的是,mb_stripos() 是大小寫不敏感的。 如果 needle 沒找到,它將返回 FALSE。

Parameters

haystack

  • The string from which to get the position of the first occurrence of needle
  • 在這個字符串中查找獲取 needle 首次出現的位置

needle

  • The string to find in haystack
  • 在 haystack 中查找這個字符串

offset

  • The position in haystack to start searching. A negative offset counts from the end of the string.
  • haystack 里開始搜索的位置。如果是負數,就從字符串的尾部開始統計。

encoding

  • Character encoding name to use. If it is omitted, internal character encoding is used.
  • 使用的字符編碼名稱。 如果省略了它,將使用內部字符編碼。

Return Values

  • Return the numeric position of the first occurrence of needle in the haystack string, or FALSE if needle is not found.
  • 返回字符串 haystack 中 needle 首次出現位置的數值。 如果沒有找到 needle,它將返回 FALSE。

Example

<?php
/**
 * Created by PhpStorm.
 * User: zhangrongxiang
 * Date: 2018/2/3
 * Time: 下午3:47
 */

$str = "PHP is the best language on the world!";
echo mb_stripos( $str, "php" ) . PHP_EOL; //0
echo mb_stripos( $str, "Best" ) . PHP_EOL; //11

// !== 嚴格比較
if ( mb_stripos( $str, "Php" ) !== false ) {
	echo "exists" . PHP_EOL;
	//php is the best language on the world!
	echo mb_strtolower( $str ) . PHP_EOL;
}

echo mb_stripos( $str, "THE", 10 ) . PHP_EOL;//28

文章參考


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM