位置: 编程技术 - 正文

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

  • 二手车过户需要带什么资料
  • 资源税和增值税销售额不一致
  • 生产型企业进项税加计扣除
  • 收到以前年度银行手续费发票
  • 公司费用计入什么科目
  • 股东入股的标准
  • 税控盘反写显没有数据怎么处理
  • 以前年度应收账款无法收回的账务处理
  • 行政事业单位收据样本
  • 其他综合收益损失
  • 出纳都需要做什么表格
  • 个体工商户个税减免优惠政策
  • 调用核心征管业务服务节点报错
  • 完税凭证是什么
  • 一般纳税人收取的下列款项中,应并入销售额
  • 会计报表指标也称为什么
  • 分期付款购入原材料怎么做账
  • 计提个税会计科目怎么做
  • 电脑硬件检修
  • 补助是按基本工资还是总工资
  • 工会经费会计分局
  • win7提示windows进行了未授权的更改
  • 运行网络操作系统的设备
  • 捐赠支出汇算清缴需要调增吗
  • php fgets函数的用法
  • 没收逾期未收回的包装物押金
  • 营业外收支计算公式
  • 阿里云jar包
  • 哥德堡的港口
  • 公司转让固定资产要交税吗
  • 餐厅手撕发票
  • 维修费成本怎么结转
  • 自动驾驶车祸
  • nor命令
  • 年报企业所得税的分录怎么做
  • 外地工程预缴的个人所得税是什么申报
  • pandas常见操作
  • 项目终止前期费用核销
  • 同花顺电脑版怎么看财务报表
  • 累计净值包含业绩吗
  • 教育培训行业成功案例
  • 核定征收一般纳税人进项是否可抵扣
  • 事业单位小规模纳税人增值税账务处理
  • 出口单证不全如何申报退税
  • 厂房出租自用各种费用
  • 现金支票存根金额怎么写
  • 应收账款的明细科目一般按照什么设置
  • 金税盘抄报税这是怎么个流程
  • 已提折旧是什么意思
  • 非营利医疗机构什么意思
  • Sqlserver聚集索引和非聚集索引的区别
  • mysql explain的用法(使用explain优化查询语句)
  • mysql5.5创建用户
  • win7历史记录在哪里
  • 无法将此电脑升级到最新版本的windows10
  • windows优化软件
  • task hots windows
  • win7能不能安装vs2019
  • hptasks.exe是病毒吗 是什么进程 hptasks进程说明
  • linux 使用技巧
  • mac电池不能被识别吗
  • Windows7忘记开机密码一键还原
  • windows8ip地址怎么设置
  • 关于自定义工作台的说法,正确的是
  • jquery showdialog
  • shell脚本 教程
  • jquery示例
  • python设计教程
  • python+django
  • jquery获取table指定的行列
  • android开发从入门到精通(项目案例版)
  • python面向对象编程心得体会
  • 出口免税不退税主要适用于什么情形
  • 已申报的纳税申报表怎么修改
  • 江苏国税,地税怎么交
  • 无锡税务局领导
  • 西安车辆购置税在线交费
  • 甲供材备案需要的资料
  • A级纳税人和一般纳税人区别
  • 7月税务征收期
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

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

    友情链接: 武汉网站建设