位置: 编程技术 - 正文

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

  • 土地增值税怎么计算
  • 资产减值损失纳税调增还是调减
  • 购入国内旅客运输服务
  • 验收入库材料结转怎么写
  • 银行商业承兑汇票到期怎么兑现
  • 共同控制合营企业
  • 宾馆收入应按什么计算
  • 企业所得税扣除凭证
  • 关联方费用分摊是否要调账
  • 应付职工薪酬的一级科目
  • 溢价发行债券的发行价格怎么计算的
  • 专利权转让的净收益计入
  • 抵缴以前年度所得税怎么做?
  • 税控盘年费去哪里交
  • 拓展培训费如何开票
  • 接收虚开增值税专用发票要判刑吗
  • 预收房租款如何入账
  • 关于开票时纳税的规定
  • 用于非增值税应交税费
  • 企业案例描述
  • 利息发票能开专票吗
  • 员工报销费用
  • 应收代位偿款
  • 营销活动的意义是什么
  • 增值税影不影响企业利润
  • 个税逾期申报怎么缴纳罚款
  • 住院材料费包括哪些
  • 桌面图标变成了白色的
  • 苹果电脑怎么截屏ctrl加什么
  • 路由器和光猫上的无线网络名称一样吗
  • 普票被退回如何处理
  • 筹资费用的含义
  • php面向对象实例
  • 存出投资款现金流量表选什么
  • windows 11硬件
  • executor进程
  • myfastupdate.exe - myfastupdate是什么进程文件 有什么用
  • kazaalite.exe是什么进程 kazaalite进程有什么用
  • 纳税人转登记期限
  • 房屋权属变更什么意思
  • 代扣代缴的附加税怎么入账
  • 前端生成docx
  • 简易html代码
  • 腾讯一面问什么
  • 银行回单打回来会计要做什么
  • 养殖场租赁发票图片
  • 员工宿舍的物业费要交个税吗
  • 期末调整汇兑损益计算
  • 微擎框架下载
  • mysql union or
  • 非正常户管理办法
  • 公司法人代表可以有几个
  • 增值税税率调整为13%从什么时候开始实行
  • 已出库的成品退货怎么办
  • 其他应收款在现金流量表怎么填
  • 企业取得交易性金融资产的主要目的是
  • 销项税和进项税的区别
  • 购入固定资产的增值税计入成本吗
  • 退回货款给客户怎么做会计分录
  • 外派人员房租
  • 增值税进项发票抵扣认证流程
  • 445端口 关闭
  • 在windows中下列叙述正确的是什么
  • 教你怎么制作麻雀胶
  • 如何关闭windows防火墙
  • ubuntu20.04关闭图形界面命令
  • mac开机慢开机以后特别卡
  • linux eval命令
  • win7自带防火墙关闭后自己打开啥原因
  • linux怎样过滤一个关键字
  • virtualbox怎么打开虚拟机
  • pycharm远程调试代码
  • 笔记本等待网络准备好
  • unity的协程
  • linux shutdown命令详解
  • 适配是什么
  • webview自定义视频播放器
  • 2022河南省地方专项计划分数线
  • 深圳海关属于省级吗
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

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

    友情链接: 武汉网站建设