str_starts_with

函式
str_starts_with ( $haystack, $needle )
引數
  • (string) $haystack The string to search in.
    Required:
  • (string) $needle The substring to search for in the `$haystack`.
    Required:
返回值
  • (bool) True if `$haystack` starts with `$needle`, otherwise false.
定義位置
相關方法
str_ends_withtimer_startstart_wp_post_statesrest_get_date_with_gmt
引入
5.9.0
棄用
-

str_starts_with: 這是一個PHP函式,用於檢查一個字串是否以另一個字串開始。它需要兩個引數,$haystack 和 $needle。如果$haystack以$needle開頭,則返回true,否則返回false。

PHP 8.0中新增的`str_starts_with()’函式的多元填充。

執行區分大小寫的檢查,表明乾草堆是否以 needle 開頭。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function str_starts_with( $haystack, $needle ) {
if ( '' === $needle ) {
return true;
}
return 0 === strpos( $haystack, $needle );
}
}
function str_starts_with( $haystack, $needle ) { if ( '' === $needle ) { return true; } return 0 === strpos( $haystack, $needle ); } }
function str_starts_with( $haystack, $needle ) {
		if ( '' === $needle ) {
			return true;
		}

		return 0 === strpos( $haystack, $needle );
	}
}

常見問題

FAQs
檢視更多 >