位置: 编程技术 - 正文
推荐整理分享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参数 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字符串型数据的定义方式)
加入一笔记录到表bankMoney,并查询此表中userID= Zhangsan的所有存款的总金额。
在这里再??乱幌麓娲⒐?痰?种传回值(方便正在看这个例子的朋友不用再去查看语法内容):1.以Return传回整数2.以output格式传回参数3.Recordset
传回值的区别:
output和return都可在批次程式中用变量接收,而recordset则传回到执行批次的客户端中。实例3:使用带有复杂 SELECT 语句的简单过程 下面的存储过程从四个表的联接中返回所有作者(提供了姓名)、出版的书籍以及出版社。该存储过程不使用任何参数。
实例4:使用带有参数的简单过程
实例5:使用带有通配符参数的简单过程
实例6:if...else存储过程,其中@case作为执行update的选择依据,用if...else实现执行时根据传入的参数执行不同的修改.
深入分析SqlServer查询计划 对于SQLServer的优化来说,优化查询可能是很常见的事情。由于数据库的优化,本身也是一个涉及面比较的广的话题,因此本文只谈优化查询时如何看懂SQ
sql 判断字符串中是否包含数字和字母的方法 判断是否含有字母selectPATINDEX('%[A-Za-z]%',‘ads')=0(如果存在字母,结果1)判断是否含有数字PATINDEX('%[0-9]%',‘sdf" class="img-responsive" alt="谈谈sqlserver自定义函数与存储过程的区别(sql自定义)">
友情链接: 武汉网站建设