位置: 编程技术 - 正文

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

  • 消费税是什么意思大白话
  • 小规模减免的增值税怎么做账
  • 注册资本 投资比例
  • 金税盘可以用安卓的线吗
  • 摊销广告费会计分录
  • 公司茶水间有什么
  • 检测费用可以开什么发票
  • 库存商品暂估后怎么结转
  • 企业开出的普票和专票对税额有影响吗
  • 公司注册住所要求
  • 政策性搬迁资产损失情况怎么写
  • 劳务派遣公司收取劳务费应开具什么票
  • 药品回扣2021
  • 结转贸易方式
  • 开发票六位代码
  • 毛利润和纯利润的计算公式
  • 企业所得税季报人数怎么填
  • 上月留抵进项抵扣分录
  • window10永久
  • 销售部门的固定资产折旧计入什么科目
  • 如何调整文件夹内文件的顺序
  • 企业年报系统怎么进
  • 企业转让房产需要开具发票吗
  • 房租收入怎么做会计分录
  • php设计思路
  • macos big sur值得升级吗
  • 网线插上还是显示红叉
  • php编程基础与实例教程
  • 哪些费用可以在开办费中列支
  • php文件上传用什么请求方法
  • 加计扣除减免政策
  • 强化学习之stable_baseline3详细说明和各项功能的使用
  • 购建或者生产符合资本化条件的资产
  • 研发支出什么时候转管理费用
  • 房屋租赁需要计增值税吗
  • 残保金计提和缴纳分录
  • sql注入漏洞不会出现在哪个位置
  • 代扣代缴个人社保账务处理
  • centos安装nmtui
  • 环保税计税依据怎么算
  • 免征增值税和增值税免税
  • 库存商品转出
  • 教育培训行业人员
  • 信用证保证金账户属于什么账户性质
  • 长期待摊费用是摊销费用吗
  • 用友t3建账行业性质怎么选
  • 酒店客房收入如何分配
  • 子公司计提的盈余公积合并抵消
  • 房地产企业按简易计税
  • 房地产企业取得政府补助
  • 我国流转税有哪些
  • 单位收走三方协议
  • 专项应付款科目编码是多少
  • 未认证发票进项怎么处理
  • 固定资产折旧的会计科目
  • 金蝶k3怎么打印科目余额表
  • 企业计提坏账准备遵循的会计信息质量要求是
  • 退资本金现金流量表走哪一项
  • 以现金支付办公用品费440元
  • 美国支票上的收款人地址不对怎么办
  • 实收资本小于注册资本账务处理
  • 如何设置固定资产的部门对应这就
  • sql server常用
  • windows server 2016最大内存
  • bios更改
  • win10默认edge浏览器
  • win7系统鼠标指针异常
  • win8开不了机怎么系统还原
  • iptables防火墙规则
  • 前端node跨域处理
  • awk 查找
  • 动态加载原理
  • 安卓模拟器错误怎么办
  • jquery如何调用
  • jquery.flot
  • auto.js获取剪切板内容
  • 水电费的增值税专用税可抵扣进项
  • 国家税务总局四川省电子税务局界面
  • 成本费用总额在报表哪里看
  • 计提缴纳城建税分录
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

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

    友情链接: 武汉网站建设