位置: 编程技术 - 正文

PHP字符串函数strtr()的用法(php中字符串函数)

编辑:rootadmin
strtr

推荐整理分享PHP字符串函数strtr()的用法(php中字符串函数),希望有所帮助,仅作参考,欢迎阅读内容。

文章相关热门搜索词:php字符串型数据的定义方式,php字符串定义,php 字符串函数,php 字符串函数,在php中,字符串有哪些表示形式,php string函数,php 字符串函数,php 字符串函数,内容如对您有帮助,希望把文章链接给更多的朋友!

(PHP 4, PHP 5)

strtr — 转换指定字符

说明 string strtr ( string $str , string $from , string $to ) string strtr ( string $str , array $replace_pairs )

该函数返回 str 的一个副本,并将在 from 中指定的字符转换为 to 中相应的字符。 比如, $from[$n]中每次的出现都会被替换为 $to[$n],其中 $n 是两个参数都有效的位移(offset)。

如果 from 与 to 长度不相等,那么多余的字符部分将被忽略。 str 的长度将会和返回的值一样。

If given two arguments, the second should be an array in the form array(&#;from&#; => &#;to&#;, ...). The return value is a string where all the occurrences of the array keys have been replaced by the corresponding values. The longest keys will be tried first. Once a substring has been replaced, its new value will not be searched again.

In this case, the keys and the values may have any length, provided that there is no empty key; additionally, the length of the return value may differ from that of str. However, this function will be the most efficient when all the keys have the same size.

参数

str

待转换的字符串。

from

字符串中与将要被转换的目的字符 to 相对应的源字符。

to

字符串中与将要被转换的字符 from 相对应的目的字符。

replace_pairs PHP字符串函数strtr()的用法(php中字符串函数)

参数 replace_pairs 可以用来取代 to 和 from 参数,因为它是以 array(&#;from&#; => &#;to&#;, ...) 格式出现的数组。

返回值

返回转换后的字符串。

如果 replace_pairs 中包含一个空字符串("")键,那么将返回 FALSE。 If the str is not a scalar then it is not typecasted into a string, instead a warning is raised and NULL is returned.

范例

Example #1 strtr() 范例

<?php$addr=strtr($addr,"äåö","aao");?>

The next example shows the behavior of strtr() when called with only two arguments. Note the preference of the replacements ("h" is not picked because there are longer matches) and how replaced text was not searched again.

Example #2 使用两个参数的 strtr() 范例

<?php$trans=array("hello"=>"hi","hi"=>"hello");echostrtr("hiall,Isaidhello",$trans);?>

以上例程会输出:

The two modes of behavior are substantially different. With three arguments, strtr() will replace bytes; with two, it may replace longer substrings.

Example #3 strtr() behavior comparison

<?phpechostrtr("baab","ab",""),"n";$trans=array("ab"=>"");echostrtr("baab",$trans);?>

以上例程会输出:

参见

str_replace() - 子字符串替换 preg_replace() - 执行一个正则表达式的搜索和替换

PHP字符串函数substr_replace()的用法 substr_replace(PHP4,PHP5)substr_replace替换字符串的子串说明mixedsubstr_replace(mixed$string,mixed$replacement,mixed$start[,mixed$length])substr_replace()在字符串string的副本中将由s

PHP字符串函数trim()的用法 trim(PHP4,PHP5)trim去除字符串首尾处的空白字符(或者其他字符)说明stringtrim(string$str[,string$charlist=tnrx0B])此函数返回字符串str去除首尾空白字符后的

PHP字符串函数substr_count()的用法 substr_count(PHP4,PHP5)substr_count计算字串出现的次数说明intsubstr_count(string$haystack,string$needle[,int$offset=0[,int$length]])substr_count()返回子字符串needle在字符串haystack

标签: php中字符串函数

本文链接地址:https://www.jiuchutong.com/biancheng/278796.html 转载请保留说明!

上一篇:PHP字符串函数vfprintf()的用法(php字符串赋值)

下一篇:PHP字符串函数substr_replace()的用法(php字符串型数据的定义方式)

  • 关税完税价格是指什么意思
  • 教育附加税税率多少?
  • 主管税务机关是否参与清算
  • 怎么交税费
  • 专票上不小心印上字了,怎么去除
  • 对外捐赠固定资产属于营业外支出吗
  • 高新技术企业入库难吗
  • 工资发放凭证由谁出具
  • 联营返点收入账务处理
  • 出口发票税率是怎么算的
  • 进口商品不提供发票合法吗
  • 哪些是非累计带薪缺勤?
  • 企业接受基金投资的规定
  • 利润表中企业所得税
  • 固定资产处置如何入账
  • 购买国债兑现时要交税吗
  • 电子承兑汇票怎么打印出来
  • 雇主责任险税务处理
  • 个人偶然所得捐赠扣除标准
  • 企业接受非现金资产投资的账务处理
  • 小规模税收减免
  • 农贸市场可以收什么的费
  • 收到苗木发票怎么做账
  • 小规模纳税人增值税免税政策
  • 开发票时已交的税金怎么做帐?
  • xp系统鼠标右键不能用怎么办
  • 兼职人员工资如何扣税
  • 付的押金冲抵部分怎么算
  • 无偿受赠房产出售税费
  • 消防工程改造方案
  • 城建税教育费附加和地方教育费附加税率
  • 存货报废的税务处理及会计处理
  • 原材料明细账有记税吗
  • 运输发票的抵扣税率
  • php读取文件
  • 年报中投资总额怎么填
  • php模板引擎执行时间
  • 暂估入库的商品能出库吗
  • php接口技术实例分析
  • 员工多交的个人社保
  • 核销已计提坏账的应收账款
  • dict.setdefault()在python中设置默认值
  • 织梦如何添加浮动广告
  • mongodb官方文档中文
  • 发票的规格型号有字数限制吗
  • sql server 2008数据库没有备份文件恢复
  • 出售专利技术收增值税吗
  • 房产税的计算方式
  • 异地预缴增值税后本地怎么申报
  • 因管理不善材料被盗应记啥科目
  • 可变现净值是什么意思
  • 多打的投资款怎么入账
  • 增资协议书范本合同
  • 母公司给子公司担保
  • 个体工商户对公账户需要交税吗
  • 企业应按照有关规定结合本企业
  • 简述什么是实收资本
  • 年末未分配利润总额计算公式
  • 专栏设计模板
  • Linux系统配置网关
  • win8怎么安装微信
  • win10怎么添加打印机
  • win10飞行模式开关是灰色的
  • Linux操作系统中怎么永久设置环境变量?
  • linux根目录和主目录
  • unityrpg
  • js动态表格可修改表格数据
  • 一系列优秀的Android开发资料
  • ubuntu14重置密码
  • shift妙用之解决shell编程中的入参问题
  • 变量代码是什么
  • javascript总结笔记
  • jquery日历框有长期的选项
  • javascript 自动执行
  • Python实现HTTP协议下的文件下载方法总结
  • 代码实现观察者模式
  • 北京市国家税务局网站官网
  • 增值额未超过扣除项目金额20%是什么意思
  • 光明区新区
  • 营改增后如何纳税
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

    网站地图: 企业信息 工商信息 财税知识 网络常识 编程技术

    友情链接: 武汉网站建设