Examples of...
Popular examples
Top Examples
Examples of Str_replace() in PHP
Str_replace() in PHP
The str_replace() function replace all occurrences of the search string with the replacement string
mixed str_replace ( mixed $search , mixed $replace , mixed $subject <, int &$count > )
This function works by the following rules:
* If the string to be searched is an array, it returns an array
* If the string to be searched is an array, find and replace is performed with every array element
* If both find and replace are arrays, and replace has fewer elements than find, an empty string will be used as replace
* If find is an array and replace is a string, the replace string will be used for every find value
Examples:
<?php
echo str_replace("world","Peter","Hello world!");
?>
output: Hello Peter!
<?php
$arr = array("blue","red","green","yellow");
print_r(str_replace("red","pink",$arr,$i));
echo "Replacements: $i";
?>
output: Array
(
<0> => blue
<1> => pink
<2> => green
<3> => yellow
)
Replacements: 1
Is this example useful?
To share this example, copy and paste this code into your website, blog or forum:
mixed str_replace ( mixed $search , mixed $replace , mixed $subject <, int &$count > )
This function works by the following rules:
* If the string to be searched is an array, it returns an array
* If the string to be searched is an array, find and replace is performed with every array element
* If both find and replace are arrays, and replace has fewer elements than find, an empty string will be used as replace
* If find is an array and replace is a string, the replace string will be used for every find value
Examples:
<?php
echo str_replace("world","Peter","Hello world!");
?>
output: Hello Peter!
<?php
$arr = array("blue","red","green","yellow");
print_r(str_replace("red","pink",$arr,$i));
echo "Replacements: $i";
?>
output: Array
(
<0> => blue
<1> => pink
<2> => green
<3> => yellow
)
Replacements: 1
Is this example useful?
To share this example, copy and paste this code into your website, blog or forum:
Comments
To leave a comment, you must register for free a> or if you are already registered log in.
Has not written any comments yet.
Has not written any comments yet.
Related examples
Htmlspecialchars PHP Posted on 2011-01-15 12:38:54
The htmlspecialchars() function converts special characters to HTML entities
string htmlspecialchars ( string $string )
The translations ...Htmlspecialchars_decode PHP Posted on 2011-01-15 12:35:47
The htmlspecialchars_decode() function convert special HTML entities back to characters
string htmlspecialchars_decode ( string $string )...Htmlentities PHP Posted on 2011-01-15 12:33:50
The htmlentities() function convert all applicable characters to HTML entities
string htmlentities ( string $string )
This function is id...Html_entity_decode PHP Posted on 2011-01-15 12:30:04
The html_entity_decode() function converts all HTML entities to their applicable characters.
The html_entity_decode() function is the opposi...Explode PHP Posted on 2011-01-15 12:26:14
The explode() function split a string by string into an array.
array explode ( string $delimiter , string $string )
delimiter: The bounda...