PHP日記(一)字串操作 php拆分字串 php字串合并 php字串換

來源:互聯網
上載者:User
一、字串的格式化

1、字串的處理:trim()、ltrim()、rtrim()

$name=trim($_POST['name']);$name=trim($_POST['password']);$name=trim($_POST['email']);

trim()函數可以去除字串的開始位置和結束位置的空格,並將結果字串返回,預設情況下去除的字元是分行符號和斷行符號符(\n和\r),水平和垂直定位字元(\t和X0B)

ltrim()函數只從字元的開始處(左邊)去除空格

rtrim()函數只從函數的結束處(右邊)去除空格

2、格式化字串以便顯示

①使用HTML格式化:n12br()函數

在字串中的新行(\n)之前插入分行符號


結果
One line.Another line.

②為列印輸出而格式化字串

printf()結構

$s="world");printf("Hello %s",$s);

3.改變字串中的字母大小寫

函數 描述 使用 $subject=Hello World 返回值
strtoupper() 將字串轉為大寫 strtoupper($subject ) HELLO WORLD
strtolower() 將字串轉為小寫 strtolower($subject ) hello world
ucfirst() 如果字串第一個字元是字元,將其轉為大寫 ucfirst($subject ) Hello world
ucwords() 將字串的每個單詞的首字母大寫 ucwords($subject ) Hello World


---------------------------------------------------------
未完

以上就介紹了PHP日記(一)字串操作,包括了php,字串方面的內容,希望對PHP教程有興趣的朋友有所協助。

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.