PHP 大小寫轉換

2022-03-15 19:57:49 字數 1270 閱讀 4528

php 大小寫轉換

1.將字串轉換成小寫

strtolower(): 該函式將傳入的字串引數所有的字元都轉換成小寫,並以小定形式放回這個字串.

例:<?php

$str = "i want to fly";

$str = strtolower($str);

echo $str;

?>

輸出結果:

i want to fly

2.將字元轉成大寫

strtoupper(): 該函式的作用同strtolower函式相反,是將傳入的字元引數的字元全部轉換成大寫,並以大寫的形式返回這個字串.用法同strtolowe()一樣.

3.將字串首字元轉換成大寫

usfilst(): 該函式的作用是將字串的第乙個字元改成大寫,該函式返回首字元大寫的字串.用法同strtolowe()一樣.

4.將字串每個單詞的首字元轉換成大寫

ucwords(): 該函式將傳入的字串的每個單詞的首字元變成大寫.如"hello world",經過該函式處理後,將返回"hello word".用法同strtolowe()一樣.

5.php字串相等比較函式

if (preg_match("/$str1/i",$str2))

mysql查詢預設是不區分大小寫的

mysql查詢預設是不區分大小寫的 如:

1. select * from table_name where a like 'a%' 

2. select * from table_name where a like 'a%'

select * from table_name where a like 'a%'

select * from table_name where a like 'a%'

效果是一樣的。

要讓mysql查詢區分大小寫,可以:

1. select * from table_name where binary a like 'a%' 

2. select * from table_name where binary a like 'a%'

select * from table_name where binary a like 'a%'

select * from table_name where binary a like 'a%'

也可以在建表時,加以標識

1. create table table_name( 

2. a varchar (20) binary 

3. )

PHP 字元轉換大小寫

將字串轉化為小寫 str abcdef echo strtolower str 輸出 aabcdef 將字串轉化為大寫 str abcdefd echo strtoupper str 輸出 abcdefd 使字元的第乙個字母小寫 echo lcfirst hello world 輸出 hello w...

大小寫轉換

小寫數值轉大寫 xieshuxu 傳入轉換字串 傳入整數單位 如 元 傳入小數點後一位單位 如 角 傳入小數點後兩位單位 如 分 public string xiaotoda string xiao,string one,string two,string tree if xiao.indexof ...

大小寫轉換

problem description x現在要學習英文以及各種稀奇古怪的字元的了。現在他想把一串字元中的小寫字母變成大寫字元,大寫字母變成小寫字母,其他的保持不變。input 輸入有多組。每組輸入乙個字串,長度不大於80,不包含空格。output 輸出轉換後的字串 sample input a b...