位置: 编程技术 - 正文

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

  • 小规模纳税人企业所得税计算
  • 汇算清缴时纳税调整表调增金额是怎么算出来的
  • 一般纳税人结转增值税
  • 金蝶k3如何设置凭证保存自动新增
  • 简易计税开的发票可以抵扣吗
  • 适用会计制度备注怎么填?
  • 房产税和土地使用税会计分录
  • 融资租入的办公楼属于固定资产吗
  • 什么叫应纳税额什么与什么的比率叫做税率
  • 建筑行业开工程票,材料抵扣有没有比例
  • 固定资产出租后还要折旧吗
  • 负债表应交税费为负数
  • 忘了报税算偷税漏税吗
  • 以旧换新要按商品价格吗
  • 进项发票可以抵扣吗
  • 进项增值税发票怎么认证
  • 专票密码区出来了一点有关系吗
  • 变更税务登记证法人需要哪些资料
  • 企业购买设备可以税前扣除吗
  • 合并报表收费
  • 经营租赁交什么税种
  • 接受捐赠后会引起
  • 旅游业小规模纳税人亏损怎么填报
  • 防伪税控发票维修流程
  • 华为手机麦克风在哪里
  • win10右键个性化提示该文件没有与之关联
  • 公司为员工购买社保流程
  • 王者荣耀花木兰打法教学
  • 购买财务软件申请怎么写
  • 公司的对公账户
  • 股东分红缴纳个税时间
  • php生成html
  • 购货折让会计分录
  • 应纳所得税额税率表
  • 工商变更后税务会自动变更吗
  • 利息资本化怎么计算
  • css鼠标移入移出切换事件
  • 税费的审计
  • 养老保险产生的利息怎么入账
  • 增值税普通发票查询真伪
  • 收到政府补贴的账务处理
  • 怎么计算多个表格的某一数据
  • 一般纳税人之间转让土地使用权交哪些税金
  • 增值税专用发票和普通发票的区别
  • 购买办公用品没有发票可以入账吗
  • 高并发数据库解决方案
  • 失控发票未付款什么意思
  • 库存商品什么时候确认收入
  • 用材料抵扣货款通知怎样写
  • 商标 入账
  • 酒店会计的账务处理
  • 员工体检的发票在哪里开
  • 经营性应付项目减少对经营活动现金
  • 年底不发工资 员工离职
  • 盈余和利润是不是一个概念
  • 为什么要计提工资附加费
  • Mysql version can not be less than 4.1 出错解决办法
  • 提升英语
  • Windows Server 2008之数据安全保护
  • windows route metric
  • 键盘和鼠标冲突
  • linux 删除文件夹里的所有文件
  • centos桌面调出命令行
  • shell检查语法错误
  • win8怎么设置成win7菜单
  • win7蓝屏0x000000d1
  • windows8应用商店在哪
  • win10开始菜单样式
  • win7 64位系统使用dos命令快速提高u盘传输速度的技巧
  • win10局域网无法上网
  • javascript有哪些类型
  • unity物理引擎原理
  • 基于python语言
  • python设计作品
  • psi python
  • jquery滚动插件
  • 社保ukey怎么使用
  • 河北公示信息网
  • 税务清查工作总结
  • 金税盘和uk
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

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

    友情链接: 武汉网站建设