位置: 编程技术 - 正文

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

  • 无偿使用房产需要交哪些税
  • 增值税专用发票使用规定 最新
  • 新冠肺炎捐赠账务处理
  • 银行应发贷款和实际收到的贷款为什么不一致
  • 公司自有房产出租营业执照范围
  • 个体工商户报税一年几次
  • 汇算清缴退款怎么入账
  • 购买业务委托书计入什么科目
  • 劳务所得报酬
  • 企业的房屋是否能确认为存货?为什么?(简单描述即可)
  • 环保专项资金可以转让吗
  • 公司报销专用发票
  • 企业收到退回商品的会计分录
  • 无形资产后续支出计入什么科目
  • 修理费的定额发票还可以报销吗?
  • 实际入库数量怎么算
  • 餐饮公司收到的拍摄服务票做什么费用
  • 增资扩股投资方要交印花税吗
  • 合同印花税多交了怎么退
  • 汇算清缴需要补税
  • 税收的凭证有哪几种
  • 应付款转收入条件
  • 网上申报城建税及附加怎么操作
  • 一般纳税人怎么计算增值税
  • 可转换公司债券账务处理
  • 微软发布新windows
  • 发票登记薄的式样
  • 增值税预缴税款表电子版下载
  • 请问王者荣耀是谁发明的
  • mac系统自带软件有哪些
  • 更改macbook
  • 少收的应收款和应付账款
  • 土地增值税增值额怎么算
  • code ide
  • 车辆开具发票后会计分录?
  • 工业企业的费用
  • vue 右键菜单
  • 商场返现活动怎么入账
  • 企业的罚款支出指企业的行政罚款
  • 百度统计网址
  • php正则表达式匹配字符串
  • 分页的实现
  • web防盗链
  • 对于企业无法支付的应付账款
  • js怎么注册
  • chat功能
  • 广告费和业务招待费扣除标准中的全年销售收入是指
  • 土石方工程开票范围
  • 银行查询余额
  • 自产货物进项税抵扣
  • 应收帐款出售给银行会计分录
  • 公益性捐赠支出纳税调整
  • mongodb unwind
  • 帝国cms批量excel导入文章
  • 小规模纳税人怎么开增值税专用发票
  • 会议服务费免税吗
  • 海关进口增值税专用缴款书
  • 宾馆购买的床财务怎么做账
  • 支付技术转让费所得税处理
  • 代理服务费计入什么科目
  • 小微企业增值税起征点是多少
  • 安装metpy
  • winxp系统介绍
  • 如何在苹果电脑上下载软件
  • centos7 安全配置
  • centos7 lvs
  • 如何设置windows密码
  • win7开机提示重启怎么办
  • win8设置无线网络
  • javascript学习指南
  • javascript的面向对象
  • autorun病毒怎么清理
  • nodejs项目实例
  • android进程间通信机制有哪些
  • 游戏引擎在游戏开发中的核心作用
  • JavaScript定义变量
  • 资源税的税目有7个,其中不包括
  • 福建地方税务局招聘
  • 汽车销售顾问有前途吗
  • 18款凯美瑞中控屏
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

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

    友情链接: 武汉网站建设