位置: 编程技术 - 正文

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

  • 资本公积转增资本的限制条件
  • 基本户如果没有资金往来
  • 小规模公司交税时间
  • 企业所得税季度申报时间
  • 个税身份验证不通过
  • 纳税人销售自产门窗并负责安装
  • 股权出资登记管理办法已废止
  • 个体工商年报怎么弄
  • 对方开票怎么做账务处理
  • 装修项目展示厅费用支出列什么科目?
  • 工程服务预交税款怎么账务处理?
  • 出租屋物品损坏怎么赔偿
  • 汽车修理费需要交印花税吗
  • 增值税普通发票有什么用
  • 房地产企业转让股权缴纳土地增值税
  • 缴纳残保金和工龄有关吗
  • 原始凭证与记账凭证的填制实验报告
  • qq画画图片大全
  • basic run
  • 怎么获得最新医学类指南
  • 给客户的贴息的会计处理
  • 红冲以前年度暂估成本如何做账
  • 收到服务费发票可以计入什么科目
  • msoobe.exe是什么
  • mssvr.exe - mssvr是什么进程 什么用
  • PHP:stream_filter_remove()的用法_Stream函数
  • 一二级公路增值税税率
  • php curl_exec
  • 一分钟玩转钉钉文档是什么东西
  • php中单双引号的区别
  • 车保险费中的车险是什么
  • 库存盘点差异分录
  • 预收账款是否要缴纳增值税
  • 普票加专票超过45万怎么交税
  • 金税四期主要监控的内容
  • 小规模纳税人免税政策2022
  • 预提费用没有收到发票也没有付款
  • 发票加上税额之后怎么还多了呢
  • 购买其他权益工具投资公允大于我支付的价值
  • 发票抬头是个人的可以报销吗
  • 电影院租金一般多少为合理
  • 已认证抵扣的发票如何做账
  • 预付账款货物到了之后怎么入账
  • 出口退税免抵退税额要交城建税吗
  • 企业投资分红帐务处理?
  • 预提费用汇算清缴如何调整
  • 商业汇票的会计科目是什么
  • 给分公司开发票由总公司付款怎么办?
  • 单位统一订员工餐
  • 款已付未收到发票
  • 支付应付账款的摘要
  • 无形资产计入待摊费用
  • 银行账与实际账不符
  • 网上认证平台进不去怎么办
  • 是不是根据营业执照查询
  • 应付票据含税吗
  • 工业企业低值易耗品二级科目
  • 如何利用公式计算
  • 销售怎么写啊
  • 年数总和法计提折旧的例题
  • 如何科学设置运动负荷
  • 使用Mysql5.x以上版本出现报错#1929 Incorrect datetime value: '''' for column ''createtime''的快速解决方法
  • solaris重启服务器命令
  • win8.1应用
  • win10账户要求必须设置pin什么意思
  • win10 tab alt
  • ssh debian
  • ubuntu server initramfs
  • win7系统玩暗黑2怎样全屏
  • windows8 8.1
  • ping命令详解步骤
  • 系统干净启动
  • centos 设置定时任务执行指定脚本的方法
  • 安卓状态栏宽度
  • 脚本 python
  • Javascript字符串长度
  • 国地税改革意义
  • 国税网站怎么登录进入
  • 内蒙古电子税务局登录入口官网
  • 宜昌市西陵区国税局局长
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

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

    友情链接: 武汉网站建设