位置: 编程技术 - 正文

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

  • 经销商返点方案范文
  • 生产部的管理人员简介范文
  • 小规模纳税人企业所得税怎么计算
  • 营业收入是不是利润
  • 无形资产摊销月底最后一天怎么算
  • 季末计提所得税可以根据本年利润计算吗?
  • 税务机关和自然人属于平等主体吗
  • 房地产收入成本确认
  • 会计核算过程中的错误分析
  • 工业会计成本核算分录
  • 计提费用怎么入账
  • 抵债资产计提折旧怎么算
  • 土地评估费计入什么会计科目
  • 个税手续费退还时间
  • 国家要收回房屋土地怎么补偿
  • 直接成本和间接成本差异
  • 购销合同的会计分录怎么写
  • 汇算清缴补交需要调报表吗
  • 为什么应收和预收在一起
  • 公司向个人转账分录
  • 自建房房产税计税依据及计算方式
  • 基本户注销帐户余额怎么分配?
  • 再生资源会计科目
  • linux清理磁盘空间
  • linux查看系统信息工具
  • macbook如何安装
  • 现代服务业包括哪些
  • 税收滞纳金能不能超过本金
  • 哪些费用发票可以报销
  • php 守护进程
  • php数组实现
  • 事业单位专项款不能购买资产吗
  • PHP:pg_free_result()的用法_PostgreSQL函数
  • 公司报销医疗费用公司医保里面的钱也报吗
  • 生产员工福利计什么科目
  • 销售食品分录
  • 库存现金盘亏盘盈的原因
  • 支付工资属于费用吗
  • 领取养老金后每年会增加多少
  • 委托加工物资增值税计税依据
  • 国际税收协定有哪些主要内容
  • uniapp打开h5页面
  • 媒体查询是什么
  • 金融机构贷款准备金
  • 收据能抵成本吗
  • python深入浅出
  • 税率开成0了怎么办
  • 营业外收入汇算清缴时需要调增吗
  • 汇票贴现是什么
  • sql server 2005怎么用
  • 采购材料单表格
  • 月销售额10万以下一般纳税人免征增值税
  • 进口货物发生纳税义务时间为
  • 哪些费用计入管理费用开办费
  • 购买的银行理财产品能提前赎回吗
  • 记账凭证应交税费填写样本图片
  • 开办费入哪个会计科目
  • 会计忘记申报税款会有什么影响
  • 会计账本怎么记账
  • 公司的残保金是分摊到员工身上的吗
  • 怎么用公式计算结果填充单元格
  • mysql中的limit用法有哪些(推荐)
  • 出现错误,请联系客服
  • 微软发布linux
  • win7系统怎么启动讲述人
  • pavsrv50.exe - pavsrv50进程管理信息
  • 全球知名的中文搜索引擎
  • Linux编译内核无法启动
  • win10开始菜单图标消失
  • 你所知道的三维建模软件有哪些?
  • Zen Coding css,html缩写替换大观 快速写出html,css
  • 使用forever管理nodejs应用教程
  • shell脚本中判断字符串是否相等
  • jquery mobile开发工具
  • js中的substring
  • 真机调试什么意思
  • 文化事业建设费是什么税
  • 广西定额发票查询入口官网
  • 新企业会计准则长期待摊费用
  • 怎么查询车船税缴费记录
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

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

    友情链接: 武汉网站建设