位置: 编程技术 - 正文

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

  • 个税申报吗
  • 审计助理是做什么工作的
  • 资产减值损失影响利润吗
  • 生产型企业出口退税计算公式
  • 公司基本户如何注销
  • 可以自己制作的商品
  • 什么发票可以做替票
  • 大数据对管理会计的影响论文
  • 公司的旅游费怎么处理
  • 调整上年度所得税计提分录
  • 国税怎么查缴税明细
  • 自然人股权转让涉税信息怎么填
  • 企业交的房产税在哪打印税单
  • 先开票后预缴能跨年吗
  • 营改增后发票
  • 新注册公司季度资产为零
  • 生育津贴有什么作用
  • 资产减值损失汇算清缴调整表
  • 小规模的成本票
  • 企业所得税季报怎么申报
  • 税控盘额度
  • 出口货物国际运输流程图
  • 财政拨款收入如何记账
  • 以前年度费用如何列支
  • 个人开发是什么意思
  • web投票系统源码
  • nmap命令
  • 房地产无证销售法律风险
  • 计算应缴房产税的公式
  • 增值税发票没认证 可以重新开吗
  • 阿伦河在哪
  • 应交税费应交增值税明细账怎么填
  • 由浅入深英语怎么说
  • 新企业所得税税前扣除政策
  • uni-app是干嘛的
  • php面向对象的机制
  • python打开文本文档中文读不出来
  • 税前扣除 发票
  • 当月增加的固定资产当月不计提折旧
  • 已认证未抵扣完的进项
  • 供应商发票多开了3毛钱能做到财务费吗
  • 企业发生的广告费应计入
  • 总分公司企业所得税如何申报缴纳
  • 暂估入账的原材料有成本差异吗
  • 0税率发票什么意思
  • 蔬菜开发票到哪里开呢?
  • 印花税购销合同改为买卖合同
  • 承兑汇票私人贴息双方都违法吗
  • 文件柜质量标准
  • 预收账款是怎么算的
  • 计提工会经费会计分录怎么写
  • 长期应付款的会计编号
  • 涉税信息声明怎么提供
  • 车辆买的商业险全险,车辆出了事故,保险公司怎么赔
  • 电子发票不小心删掉了怎么办
  • 盈余公积的会计分录
  • 预付押金是否可以退回
  • a公司刚刚执行了一个采购项目
  • 手写发票还能用么
  • mac中mysql应该怎么运行
  • pd虚拟机安装安卓系统
  • freebsd使用手册
  • 极速一键装机
  • 360杀毒恢复区
  • win10 系统桌面
  • ExtJS 4.2 Grid组件单元格合并的方法
  • perl数组元素个数
  • 辅组什么词?
  • linux查找目录的命令
  • python随机数代码
  • javascript小数四舍五入多种方法实现
  • JavaScript中的数据类型
  • python脚本运行命令
  • [置顶]从lv2开始开挂的原勇者候悠闲的异世界生活
  • easyui treegrid重新加载
  • 粮食企业所得税优惠
  • 云南省电子税务
  • 烟台税务局举报电话号码
  • 2022年各大省份录取分数线
  • 电子税务局怎么删除办税员
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

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

    友情链接: 武汉网站建设