User:
Password:

Home | New Examples | Popular | Top | Submit Examples | Request Examples

For example: Metaphors, hiatuses, adjectives, nouns,...
You are here: Examples10.com > Computer - Programming > PHP > Str_replace() in PHP

Examples of Str_replace() in PHP


Str_replace() in PHP

Post by natttt
Posted on 2011-01-15 12:19:14
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?
 (20%) YES    NO (80%)


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 or if you are already registered log in.

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...
© 2010 Examples10.com · Compilation of examples, samples with definitions of all free   Legal Notice | Contact | Pending

eXTReMe Tracker