php的字符串格式化

1.字符串的整理:chop(),itrim(),trim()

trim()函数用来整理用户输入数据,如下显示:

$name=trim($name);

$email=trim($email);

tirm()函数可以去除字符串开始位置和结束位置的空格,并将结果字符串返回。默认情况下去除换行符(/n)回车符(/r)水平(/t)和垂直制表符(/x0B) 字符串结束符号(/0)和空格。

以下是来自于手册

Without the second parameter, rtrim() will strip these characters:

    * " " (ASCII 32 (0x20)), an ordinary space.
    * "/t" (ASCII 9 (0x09)), a tab.
    * "/n" (ASCII 10 (0x0A)), a new line (line feed).
    * "/r" (ASCII 13 (0x0D)), a carriage return.
    * "/0" (ASCII 0 (0x00)), the NUL-byte.
    * "/x0B" (ASCII 11 (0x0B)), a vertical tab

Example#1 Usage example of rtrim()
<?php

$text = "/t/tThese are a few words :) ...  ";
$binary = "/x09Example string/x0A";
$hello  = "Hello World";
var_dump($text, $binary, $hello);

print "/n";

$trimmed = rtrim($text);
var_dump($trimmed);

$trimmed = rtrim($text, " /t.");
var_dump($trimmed);

$trimmed = rtrim($hello, "Hdle");
var_dump($trimmed);

// trim the ASCII control characters at the end of $binary
// (from 0 to 31 inclusive)
$clean = rtrim($binary, "/x00../x1F");
var_dump($clean);

?>

上例将输出:

string(32) "        These are a few words :) ...  "
string(16) "    Example string
"
string(11) "Hello World"

string(30) "        These are a few words :) ..."
string(26) "        These are a few words :)"
string(9) "Hello Wor"
string(15) "    Example string"

函数explode() implode() join()

explode — 使用一个字符串分割另一个字符串

字符串的排序 strcmp() strcasecmp() strnatcmp()

在字符串中查找字符串 strstr() strchr() strrchr() stristr()

太多了,慢慢看手册
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值