位置: 编程技术 - 正文

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

  • 什么是边际税率高
  • 自行申报需补缴税款时征收滞纳金吗
  • 出让土地缴纳的契税怎么账务处理
  • 当月开票当月付款分录
  • 房贷利息抵个税细则 两套房
  • 股权转让溢价会计处理
  • 突然收到财付通转出的钱
  • 股票属于现金及股票吗
  • 房地产增值税预征率
  • 增值税发票增量流程网上怎么申请
  • 申报专项资金项目是什么
  • 为员工购置小车怎么做账
  • 股权转让企业所得税如何申报
  • 增值税预缴税额可以改吗
  • 抵扣联和发票联算一张发票吗
  • 出口退免税的类型
  • 公司注销时帐面清算
  • 电子产品怎么计税
  • 棚户区改造贷款管理办法
  • vs code no such file or directory
  • realpopup.exe - realpopup是什么进程
  • 外企采购回扣普遍吗
  • 自制原始发票
  • 详解php字符串替换
  • 非营利组织免税资格公示
  • php下载文件夹
  • php8.0 特性
  • 购买电脑如何入账
  • 93.transformer、多头注意力以及代码实现
  • 学习笔记:深度学习(2)——BP神经网络
  • bg命令 将作业放到后台运行
  • 卫生医疗收费专业有哪些
  • 机动车发票抵扣新规
  • dedecms模版
  • 费用发票可以抵扣进项税吗
  • 税务机关代开的增值税发票要加盖发票专用章吗?
  • 网上打印出来的手机买卖协议有效吗
  • 个人所得税隔月交么
  • 固定资产折旧会影响净利润吗
  • 如何在sql server中已有数据库进行修改
  • 银行存款日记账是企业的还是银行的
  • 信息技术服务增值税税负率是多少
  • 契税退税政策怎么操作
  • 建筑业的人工费是什么
  • 债务重组损失计入什么科目2020
  • 股东借款转实缴资本
  • 个人收到国外汇款后怎么办
  • 企业应缴纳的消费税
  • mysql主键冲突但数据不存在
  • 445端口 关闭
  • 苹果15手机价格和图片颜色
  • u深度u盘启动盘制作工具无法进入电脑
  • win8.1的开始菜单在哪
  • windows server 2016正式版下载激活安装设置教程
  • 如何把xp系统的软件删除
  • ubuntu 8.04.1 LTS 下的cpu温度监控软件lm-sensors
  • msoobe.exe是什么
  • centos做bond4
  • win8和win10双系统切换
  • win7系统安装软件重启电脑后就没了
  • win8系统找不到无线网络
  • win8.1核心版密钥
  • 安卓listview的用法
  • jquery跳出循环
  • perl数组去重
  • unity基础包
  • python3 mongodb
  • unity3d入门视频教程
  • unity hud优化
  • javascript运用
  • javascript函数大全
  • js基础
  • node express 路由
  • 长沙税务网站查询系统
  • 出口退税全流程
  • 欠税款要坐牢吗
  • 增值税税率为6%,怎么计算税额
  • 税务局网上开票平台app
  • 百旺税控客服电话
  • 税率的计算器在线计算
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

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

    友情链接: 武汉网站建设