首页 > php教程 > PHP源码 > 正文

php的字符串格式化

php中文网
发布: 2016-06-08 17:31:21
原创
1420人浏览过
<script>ec(2);</script>
1.字符串的整理:chop(),itrim(),trim()

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

$name=trim($name);

$email=trim($email);

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

以下是来自于手册

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.
    * "" (ASCII 0 (0x00)), the NUL-byte.
    * "x0B" (ASCII 11 (0x0B)), a vertical tab

Example#1 Usage example of rtrim()

$text = "ttThese are a few words :) ...  ";
$binary = "x09Example stringx0A";
$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()

太多了,慢慢看手册

PHP速学教程(入门到精通)
PHP速学教程(入门到精通)

PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号