PHP 常用 字串 函式詳解

2022-02-21 02:37:48 字數 1443 閱讀 1718

返回字串的位元組數

轉換成大寫或小寫

首字元大寫

ucwords ( string $str [, string $delimiters = " \t\r\n\f\v" ] ) : string
每個單詞首字母大寫

strcmp ( string $str1 , string $str2 ) : int
字串的比較,按照ascll碼來比較字串的大小

0-9字串擷取

strpos ( string $haystack , mixed $needle [, int $offset = 0 ] ) : int
查詢乙個字串在另乙個字串中第一次出現的位置

str_replace ( mixed $search , mixed $replace , mixed $subject [, int &$count ] ) : mixed
查詢替換

str_pad ( string $input , int $pad_length [, string $pad_string = " " [, int $pad_type = str_pad_right ]] ) : string
填充函式

str_repeat ( string $input , int $multiplier ) : string
重複函式

字串反轉

substr_compare ( string $main_str , string $str , int $offset [, int $length [, bool $case_insensitivity = false ]] ) : int
擷取比較

compare main_str from position offset with str up to length characters.

md5 ( string $str [, bool $raw_output = false ] ) : string
md5加密

非對稱性的,不可逆,能加密,不能轉變回來

不管對多少位的字串,都是加密成32位 字元和數字組成的字串

base64加密與解密

轉義函式,自動的給某些特殊的字元加上轉義符號,不會轉義$符號

返回字串,該字串為了資料庫查詢語句等的需要在某些字元前加上了反斜線

反轉義函式,自動去掉轉義符號

用在從資料庫中取出資料的時候用的

strip_tags ( string $str [, mixed $allowable_tags ] ) : string
從字元中去除html和php的標記,只保留內容

PHP常用字串函式

1 echo,print,print r,printf,sprintf 前兩個函式是輸出字串.字串中如果有變數名則被替換成其值.php程式設計師站 print r也是輸出函式,不同的是他可以輸入複雜結構的資料,比如陣列,物件 後兩個函式類似於c的同名函式.2 strchr,strlen,strtok...

php常用字串函式

一些簡單實用的函式 strlen string 獲取字串的長度。trim str,char 移除字串兩側的空白字元或其他預定義字元。ltrim str,char 移除字串左側的空白字元或其他預定義字元。rtrim str,char 移除字串右側的空白字元或其他預定義字元。strtolower str...

PHP常用字串函式

函式名 描述例項 輸入輸出 去空格或其他字元 trim 刪除字串兩端的空格或其他預定義字元 str r nhello world r n echo trim str 目標字串 清除後的字串 rtrim chop 刪除字串右邊的空格或其他預定義字元 str hello world r n echo r...