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 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):-
Screenshot1 |
<?php $string = 'This is a string, and is an example.'; $new_string = str_replace('is','',$string); echo $new_string; ?>
Output (Screenshot2):-
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) :-
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):-
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..