如何学习PHP str

如题所述

str_replace函数理解1

str_replace() 函数使用一个字符串('a')替换字符串('b')中的另一些字符。

1.另一些字符如何理解;

str_replace函数理解2

语法

str_replace(find,replace,string,count)

1.str_replace函数参数一find是否为被替换的字符串;

2.str_replace函数参数二replace是否为替换的字符串;

3.str_replace函数参数三string是否为作用的对象字符串;

4.str_replace函数参数四count是否为对替换字符串做计数;

参数

描述

find必需。规定要查找的值。

1.查找的值是否在对象字符串;

replace必需。规定替换 find 中的值的值。

string必需。规定被搜索的字符串。

count可选。一个变量,对替换数进行计数。

提示和注释

注释:该函数对大小写敏感。请使用 str_ireplace() 执行对大小写不敏感的搜索。

注释:该函数是二进制安全的。

1.str_replace对大小写是否敏感;

2.是否只要是字符串,都可进行替换,使用函数;

3.替换作用并不止是对字符串,数组同样可以作用;

4.若想统计替换了多少个字符,可以使用count参数;

5.替换也可以数组与数组之间替换,完整替换也可;

str_replace函数理解3

<?php

echo str_replace("wo","John","world!");

?>

输出:Johnrld!

带有数组和 count 变量的 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

<?php

$find = array("Hello","world");

$replace = array("B");

$arr = array("Hello","world","!");

print_r(str_replace($find,$replace,$arr));

?>

输出:

Array ( [0] => B [1] => [2] => ! )
温馨提示:答案为网友推荐,仅供参考
大家正在搜