PHP常用文字列関数及び注意事項
5478 ワード
strncmp($alias, '@', 1)
大文字と小文字を区別せず、比較結果が同じ場合は0を返します
適用例:
$result[$matches[1]] = strcasecmp($matches[2], 'desc') ? SORT_ASC : SORT_DESC;
類似関数:substr_compare
Find the position of the first occurrence of a substring in a string
Returns FALSE if the needle was not found.
false|int strpos ($haystack, $needle, $offset = 0)
Strip whitespace (or other characters) from the beginning and end of a string
string trim ( string $str [, string $character_mask = " \t
\r\0\x0B" ] )
t水平タブ、キーボードTabキーに対応する.linux改行記号、r macOs改行記号(アップルのオペレーティングシステム)、r windows改行記号0はc言語では文字列の末尾フラグとして使用するが、phpでは特に意味がない.x 0 Bはvに等しく、垂直指標記号で、最後のアルファベットがBであることに注意し、8に書かないでください.
類似関数:
ltrim
rtrim
Translate characters or replace substrings
string strtr ( string $str , string $from , string $to )
string strtr ( string $str , array $replace_pairs )
Replace all occurrences of the search string with the replacement string
mixed str_replace ( mixed $needle , mixed $replace , mixed $haystack [, int &$count ] )
Uppercase the first character of each word in a string
string ucwords ( string $str [, string $delimiters = " \t\r
\f\v" ] )
substrこの関数の3番目のパラメータに注意
Split a string by string
array explode ( string $delimiter , string $string [, int $limit = PHP_INT_MAX ] )
注意:(1)第1のパラメータは区切り文字であり、第2のパラメータは区切り文字列である.3番目のパラメータは被スタイルの総個数である.戻り値の重要な説明:
If delimiter is an empty string (""), explode() will return FALSE. A string that doesn’t contain the delimiter will simply return a one-length array of the original string. If delimiter contains a value that is not contained in string and a negative limit is used, then an empty array will be returned, otherwise an array containing string will be returned.
explode(’’,"")は、
[""]
、および空の文字列を含む配列を返す.