位置: 编程技术 - 正文

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

  • 税务局防范税收风险的措施
  • 银行电子回单有没有法律效应
  • 投资性房地产公允价值变动
  • 国家税务总局操作指引
  • 预付账款可以开发票吗
  • 经营所得汇算在哪里查
  • 事业单位补提折旧怎么处理
  • 已暂估入库原材料,确认收不到发票怎么调账
  • 个税0申报漏了2年可以补报
  • 企业所得税不超过300万怎么算
  • 建筑行业一般纳税人增值税税率是多少
  • 农业生产者销售自产农产品按9%的税率征收增值税
  • 备用金每个月可以用几次
  • 增值税的简易计税是什么意思
  • 取得的收入含税吗
  • 递延所得税当期发生额
  • 银行收回贷款本息企业怎么做分录
  • 企业买茶叶如何账务处理
  • 发票开错地方教育费附加多交了可以冲掉吗?
  • 深圳税种核定需要申报吗
  • ca浏览器组件如何下载?
  • 企业每季度预缴增值税
  • 小规模季报营业税怎么算
  • 重置申报清册是什么意思
  • 多付几分钱怎么做账
  • 非贸易企业代扣代缴增值税和附加税如何做账?
  • 电子专用发票怎么上传
  • 鸿蒙系统怎么安装电脑
  • php字符串定义
  • 计提个体户经营所得税
  • service.exe是什么进程
  • 营业利润投资收益是借方还是贷方
  • php_fileinfo作用
  • 海鸥歌曲
  • 什么情况下要预提集装箱
  • 会计核算的职能主要是从什么方面综合反映
  • dtft与dfs
  • 减值准备对方科目不能是固定资产
  • php常用类
  • 登录页面的实现方式
  • python制作chm
  • 母公司与子公司交易属于关联交易吗
  • 承兑汇票贴现会计分录怎么做
  • 不抵扣的发票需要认证吗
  • 营改增后工程分包财务
  • 发票项目要求
  • 帝国cms视频教程
  • mongodb 入门
  • 关于进项票少的解决方案
  • 如何理解合并报表抵消分录
  • 资产负债表中衍生金融资产项目应根据什么科目填列
  • 核定扣除投入产品怎么算
  • 开一般户需要基本户开户许可证吗
  • mysql中的索引有
  • 资产损失税前扣除
  • 小规模未达起征点申报表怎么填
  • 没有发票的支出怎么入账
  • 慰问金计入什么部门经济分类
  • 有限公司结业清算
  • 奖金如何做账分录
  • mysql查询慢的优化方案
  • Windows任务计划高级应用
  • 教你设置陌陌耳返
  • Windows 2000中NTFS磁盘权限应用
  • .ctc文件
  • win10 oem key
  • win10预览版和正式版
  • centos还原到初装
  • Win7系统打开D盘文件后怎么没有后退箭头
  • cocos2d游戏源码
  • 读长沙师范学院收费多少钱
  • python生成矩阵的方法
  • node.js redis
  • bootstrap怎么用
  • python中email模块
  • pycharm flask框架
  • 江苏省国家税务局电话号码
  • 财务报表盖章位置
  • 总公司和子公司是什么关系
  • vat税怎么做分录
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

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

    友情链接: 武汉网站建设