php tutorial - PHP str_replace Function - php programming - learn php - php code - php script



  • The str_replace function is used to locate and replace the specific string values in a given string.

php script Syntax :

str_replace(search, replace, subject);
click below button to copy the code. php tutorial - team

  • The str_replace function contain three arguments. The first argument defines the text to be replaced.
  • Second argument defines the replacement text.
  • Third argument defines the text that is analyzed.

php 7 Sample Code : sample php program

<!DOCTYPE html>
<html>
    <body>
        <?php
            echo str_replace('forum', 'tutorial points',
	   'welcome to wikitechy technical forum!....');
        ?>
    </body>
</html>
click below button to copy the code. php tutorial - team

php program Code Explanation :

Code Explanation for str_replace Function In PHP

  1. In this example we used string replace function for the first parameter as text to be replaced, so “forum” will be replaced by the second parameter “tutorial points” and the third parameter is the content that is from where these needs to take place, here we have “welcome to wikitechy technical forum”.

php coding Sample Output :

output for str_replace Function In PHP

  1. In the output statement “'welcome to wikitechy technical forum!....” the term “forum” has been replaced as “tutorial points”, so now we got the output as “welcome to wikitechy technical tutorial points!....”.


Related Searches to php str_replace function