View Single Post
  #27 (permalink)  
Old 10-17-2007, 03:19 AM
venkat_charya venkat_charya is offline
D-Web Sr.Programmer
 
Join Date: Mar 2007
Posts: 118
venkat_charya is on a distinguished road
Thumbs up Re: string functions and manipulations in php

hi,

Here we discussing about the replace function. In string functions of PHP there is one function called "str_replace()", which used to replace any single or set of charcter to anyother format.

Syntax
str_replace(find,replace,string,count)

find = Required. Specifies the value to find
replace = Required. Specifies the value to replace the value in find
string = Required. Specifies the string to be searched
count = Optional. A variable that counts the number of replacements


Example
<?php
echo str_replace("world","Peter","Hello world!");
?>


The output of the code above will be:
Hello Peter!

For case sensitive scenario, we can use str_ireplace() function.


Syntax
str_ireplace(find,replace,string,count)

find = Required. Specifies the value to find
replace = Required. Specifies the value to replace the value in find
string = Required. Specifies the string to be searched
count = Optional. A variable that counts the number of replacements

<?php
echo str_ireplace("WORLD","Peter","Hello world!");
?>

The output of the code above will be:
Hello Peter!


Thanks
__________________
K K Venkata Charya
Success is easy to get but difficult to retain
Reply With Quote