Wednesday 12 March 2014

string replace function

replace string function
string replace function in php programming languages.
str_replace function is called string replace function.
str_replace takes three arguments this are required arguments

str_replace(looking for, to replace, string) 

Code for string replace function (Screenshot1):-

string replace function
Screenshot1

<?php



$string = 'This is a string, and is an example.';

$new_string = str_replace('is','',$string);



echo $new_string;



?>


Output (Screenshot2):-

str_replace function php
Screenshot2
Example for String Replace function in php programming langauage. In this example i had created a String i.e, This is a string and is an example. Always keep practice to call function by making new variable so here again i am creating variable for function called new_string equal to str_replace function inside function we will pass arguments such as the first argument the word we want to replace here we will replace is from blank space in string. So our second argument is blank space and third argument is string as you can see the output from string i.e, This is a string and is an example. is replaced by i.e, Th a string and an example.

Code for string replace function with array (Screenshot3) :-

string replace function in php
Screenshot3


<?php

$find = array('is','string','example');

$replace = array('IS','STRING','');



$string = 'This is a string, and is an example.';



$new_string = str_replace($find,$replace,$string);



echo $new_string;

?>

Output(Screenshot4):-

string replace function
Screenshot4
In this example we are creating array with string replace function. $find variable array will contain the words which we want to replaced and $replace variable array will contain the word with which we had to replaced and $string variable contains the string as you can see the result string i.e, This is a string, and is an example. Is replaced by i,e. ThIS IS a STRING, and IS an .

Now why is this function is useful and where you use this function?

The example you may have select keywords you don't want to appear in may be some public post on your website.


No comments:

Post a Comment

Thanks For Comment Will get you Soon..

About Me

Welcome to Extra Tutorials! My name is Mohammed and I am the 22 year writer, website developer, and photographer behind the blog. Thanks for visiting! Tutorials Jackpot… In addition to Developer, I love to develop websites and I love to write. Starting a php Blog was inevitable for me. What began as a simple way to share all of my Tutorials with friends and family has developed into my Part time job.

Mohammed Padela

WHAT IS PHP PROGRAMMING

WHAT IS PHP PROGRAMMING
WHAT IS PHP PROGRAMMING

Follow Us

Popular Posts

Designed ByBlogger Templates