当前位置: 网学 > 编程文档 > PHP > 正文

PHP字符串处理的10个简单方法

来源:Http://myeducs.cn 联系QQ:点击这里给我发消息 作者: 用户投稿 来源: 网络 发布时间: 13/06/21
s($input, " ");

8.比较两个字符串

比较两个字符串,以确保它们是相同的。例如,判断用户第一次与第二次输入的密码是否相同,你可以使用substr_compare()函数来很容易的现实:

复制代码 代码如下:
$pswd = "secret";
$pswd2 = "secret";
if (! strcmp($pswd, $pswd2))
{ echo "The passwords are not identical!"; }


如果你想判断两个字符串不区分大小写,可以使用strcasecmp()函数。

9.转换换行符

在本文中我介绍了如何轻松转换成超超链接的URL,现在介绍nl2br()函数,这个函数能够帮助你将任何换行符转换成HTML标签。
复制代码 代码如下:
$comment = nl2br($comment);

10.应用自动换行

应用自动换行,你可以使用PHP中的这个函数:wordwrap():
复制代码 代码如下:
$speech = "Four score and seven years ago our fathers brought forth, upon this continent, a new nation, conceived in Liberty, and dedicated to the proposition that all men are created equal.";
echo wordwrap($speech, 30);

执行上面的代码,结果是:

Four score and seven years ago our fathers brought forth, upon this continent, a new nation, conceived in Liberty, and dedicated to the proposition that all men are created equal.

原文地址:http://phpbuilder.com/columns/Jason_Gilmore060210.php3
原文名:10 Easy Solutions for PHP String Manipulation
作者:W. Jason Gilmore
  • 上一篇资讯: php flv视频时间获取函数
  • 网学推荐

    免费论文

    原创论文

    浏览:
    设为首页 | 加入收藏 | 论文首页 | 论文专题 | 设计下载 | 网学软件 | 论文模板 | 论文资源 | 程序设计 | 关于网学 | 站内搜索 | 网学留言 | 友情链接 | 资料中心
    版权所有 QQ:3710167 邮箱:3710167@qq.com 网学网 [Myeducs.cn] 您电脑的分辨率是 像素
    Copyright 2008-2015 myeducs.Cn www.myeducs.Cn All Rights Reserved
    湘ICP备09003080号