PHP str_replace() 函数实例教程
定义和用法
该str_replace ( )函数代替某些字符与其他一些字符的字符串。
此功能的作品以下规则:
如果字符串被搜身是一个数组,它返回一个数组
如果字符串被搜身是一个数组,查找和替换是用每一个数组元素
如果查找和替换的阵列,并取代了少部分比找到一个空字符串将被用来作为取代
如果发现是一个数组并取代是一个字符串,字符串的替换将用于每一个寻找价值
语法
str_replace(find,replace,string,count)
Parameter | Description |
---|---|
find | 必需的。指定的价值发现 |
replace | 必需的。指定的价值,以取代的价值发现 |
string | 必需的。指定的字符串被搜身 |
count | 任择。一个变量的计数的数量更换 |
提示和说明
注:此功能是区分大小写的。使用str_ireplace ( )执行不区分大小写的搜索。
注:此功能是二进制的安全。
-------------------------------------------------- ------------------------------
范例1<?php echo str_replace("world","Peter","Hello world!"); ?>输出结果.Hello Peter!示例2
在这个例子中,我们将展示str_replace ( )同一个数组和一个计数变量:
<?php $arr = array("blue","red","green","yellow"); print_r(str_replace("red","pink",$arr,$i)); echo "Replacements: $i"; ?>输出结果
Array ( [0] => blue [1] => pink [2] => green [3] => yellow ) Replacements: 1
定义和用法
该str_rot13 ( )函数执行ROT13编码字符串。
编码的改变ROT13每信13位的字母。数字和非字母字符仍然不变
str_rot13(string)
Parameter | Description |
---|---|
string | Required. Specifies the string to encode |
提示和说明
提示:编码和解码是由相同的功能。如果你传递一个编码字符串作为参数,原来的字符串将被退回。
-------------------------------------------------- ------------------------------
例如
在这个例子中,我们将编码和解码字串使用str_rot13 ( )函数:
<?php echo str_rot13("Hello World"); echo "<br />"; echo str_rot13("Uryyb Jbeyq"); ?>输出Uryyb Jbeyq Hello World
PHP str_repeat()作用与实例教程
定义和用法
该str_repeat ( )函数重复一个字符串指定的次数。
语法
str_repeat(string,repeat)
Parameter | Description |
---|---|
string | 指定的字符串重复 |
repeat | 指定次数的字符串会重复出现。必须大于或等于0 |
<?php echo str_repeat(".",13); ?>输出结果.............
php入门教程:php rtrim()实例教程
定义和用法
该rtrim ( )函数将删除空格或其他预先确定的性质从右侧的一个字符串。
语法
rtrim(string,charlist)
参数说明
字符串必需。指定的字符串检查
charlist可选。指定的字符删除字符串。如果省略,所有的下列字符被删除:
“ 0 ” -空
“ T ”型-标签
“ ñ ” -新的生产线
“ x0B ” -垂直标签
“ r ”开始-回车
“ ” -普通的白色空间
范例1<html> <body> <?php $str = "Hello World! "; echo "Without rtrim: " . $str; echo "<br />"; echo "With rtrim: " . rtrim($str); ?> <body> <html>输出结果.Without rtrim: Hello World! With rtrim: Hello World!如果您选择“查看源文件”在浏览器窗口中,您会看到下面的HTML :
<html> <body> Without rtrim: Hello World! <br />With rtrim: Hello World! </body> </html>实例二.<?php $str = "Hello World!rn"; echo "Without rtrim: " . $str; echo "<br />"; echo "With rtrim: " . rtrim($str); ?>输出.Without rtrim: Hello World! With rtrim: Hello World!
php print() 与printf()函数教程
定义和用法
print( )函数输出一个或多个字符串。
语法
print(strings)
Parameter | Description |
---|---|
strings | Required. One or more strings to be sent to the output |
提示和说明
注:print( )函数没有实际的功能,所以你不需要使用括号的。
提示:print( )函数略低于回声( ) 。
-------------------------------------------------- ------------------------------
范例1<?php $str = "Who's Kai Jim?"; print $str; print "<br />"; print $str."<br />I don't know!"; ?>结果.Who's Kai Jim? Who's Kai Jim? I don't know!好了下面我们再来看看printf函数吧.定义和用法
在printf函数( )函数输出格式化字符串。
该arg1 , arg2 , + +参数将插入百分比( % )迹象的主要字符串。此功能的作品“一步一步” 。在第一次%的迹象, arg1插入,在第二%的迹象, arg2插入等
语法printf(format,arg1,arg2,arg++)
Parameter Description format 必需的。指定的字符串,以及如何格式的变量中。可能格式值: % % -返回百分号%数b -二进制数% C组-字符按照A SC II值%d个-签名十进制数%专-科学符号(如1 .2 e + 2)%u个-未签名的十进制数%女-浮点数(本地设置意识到) %女-浮点数(而不是本地设置意识到)% o -不八进制数的% s -弦乐%器-十六进制数(小写字母) %器-十六进制数(大写字母)格式的附加价值。这些被置于之间的%和文字(例如0.2 % ,女) : + (力量都+和-在前面的号码。默认情况下,只有负数标记) ' (指定使用什么作为填充。默认的空间。必须使用同宽符。范例: % ' x20s (此使用的“ X ”作为填充) -(左有理由变量值) [ 0 -9] (指定的最低举行的宽度的变量值) 。 [ 0-9 ] (指定小数位数或最高字串长度)注:如果有多个额外的格式使用的价值,他们必须在同一顺序如上。arg1 Required. The argument to be inserted at the first %-sign in the format string arg2 Optional. The argument to be inserted at the second %-sign in the format string arg++ Optional. The argument to be inserted at the third, fourth, etc. %-sign in the format string
提示和说明
注:如果有更多的迹象%以上的论点,您必须使用占位符。预留位置插入%后签署,由论点,数量和“ $ ” 。见三个例子。
提示:相关职能: fprintf ( ) , sprintf ( ) , vfprintf ( ) , vprintf ( )和vsprintf ( ) 。
-------------------------------------------------- ------------------------------
范例1
<?php $str = "Hello"; $number = 123; printf("%s world. Day number %u",$str,$number); ?>
输出结果
Hello world. Day number 123实例二.
<?php $number = 123; printf("%f",$number); ?> |
结果.
123.000000 |