位置: 编程技术 - 正文

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字符串型数据的定义方式)

  • 土地入账成本包含哪些
  • 个人所得税如何查询工资
  • 灭火器属于什么经营范围
  • 收到税务局附加税退税税款的分录
  • 发票分开开票
  • 一般劳务报酬和税收区别
  • 投资性房地产处置时为什么要结转其他综合收益
  • 商业房产出租和租赁区别
  • 回迁房的交易流程
  • 申请国家知识产权的条件
  • 客户要开票资料干嘛
  • 汽车配件的税收编码是多少
  • 查账征收的成本费用
  • 个税滞纳金如何调增所得税费用
  • 外贸企业出口收入确定
  • 抵押贷款逾期怎么处理抵押物
  • 货币资金核算流程设计
  • 删除文件时错误是怎么回事
  • 绝地求生未来之役手游下载
  • 盘盈的固定资产怎么做账务处理
  • 财政补贴会计入养老金一起发放吗
  • 上海个人所得税计算器
  • deepin安装windows字体
  • word基本怎么使用
  • php+js
  • 主营业务收入明细账
  • 处理固定资产的账务处理
  • 会计分录编制的步骤
  • 会计月末做账
  • 第4章 数据处理思维导图
  • 营改增后,个人转让房屋的个人所得税
  • PHP:finfo_open()的用法_fileinfo函数
  • 购货人与收货人的关系
  • 浅谈PHP发送HTTP请求的几种方式
  • pytorch基础
  • 税局 不负责任
  • 应收账款的账期是什么意思
  • 织梦cms怎么样
  • 诉讼代理费计入事业单位什么科目
  • 哪些企业不需要做安评
  • 计提 增值税
  • 个人独资企业可以变更法人吗?
  • 个人所得税进一步改革方向
  • 商贸公司分录大全
  • 金税四期能监控到公户吗
  • 预付账款期末可能有余额吗
  • 加息法实际利率计算公式
  • 建造生产线计入什么科目
  • 确认收入时,也必须确认资产或债务
  • 长期股权投资如何入账
  • 购买金税盘未抵税怎么办
  • 当月增加的固定资产当月不计提折旧
  • 给客户购物卡如何充钱
  • 软件生产企业培训内容
  • 收购农产品没有发票
  • 分公司有独立账套吗
  • sqlserver多行转多列
  • SQL Server Bulk Insert 只需要部分字段时的方法
  • centos yum报错
  • kcleaner.exe是什么
  • xp系统如何更新
  • centos为什么没有桌面
  • win7 设置
  • Unity3D-SLua+ProtocolBuffers构建说明
  • Unity3D游戏开发标准教程吴亚峰于复兴人民邮电出版社
  • javascript原生写法
  • js按位运算符
  • node.js报错998
  • unity3d怎么全屏
  • Intermediate Unity 3D for iOS: Part 2/3
  • vue list清空
  • unity3d课程
  • static function FindObjectsOfType (type : Type) : Object[]
  • 票据代码和票据号码是什么意思
  • 江苏国税电子税局
  • 税控盘怎么分发
  • 农村房屋改造问题向谁举报
  • 鄞江在哪里
  • 贵州税务发票流向查询
  • 个人利息收入属于什么收入
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

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

    友情链接: 武汉网站建设