PHP: Basic String Manipulation 基本的字符串操作
String Manipulation
Single Quoted String
1 | $str="PHP"; |
Output
1 | Welcome to learn $str |
Because single quoted treat is as a string as a whole.
Double Quoted String
1 | <?php |
Output
1 | Welcome to learn PHP |
Double quotation has the ability to detect the keyword(variable).
strtoupper(argument)
Change to uppercase
1 | <?php |
Output
1 | HELLO PEOPLE |
strtolower(argument)
Change to lowercase
1 | <?php |
Output
1 | uppercase=HELLO PEOPLE |
ucfirst(argument)
Change first letter to uppercase
1 | <?php |
Output
1 | Hello people |
lcfirst(argument)
Change first letter to upper case for each words
1 | <?php |
Output
1 | hELLO PEOPLE |
strcmp(argument)
To compare string in terms of number of characters
1 | <?php |
Output
1 | 7 |
HELLO had to add more required same letters to right in order to be the same
1 | <?php |
Output
1 | -2 |
strlen(argument)
To display the number of characters
1 | <?php |
Output
1 | 12 |
This included spacing,
substr($str,pos)
Cut characters of string
1 | <?php |
Output
1 | EOPLE |
The first 7 letters is cut
trim($str,”abc”)
To cut characters by specify the characters
1 | <?php |
Output
1 | O PEOP |
The HEL is being cut from the string
本部落格所有文章除特別聲明外,均採用 CC BY-NC-SA 4.0 許可協議。轉載請註明來自 Codes!