Find and Replace String - Php

How to find and replace string using php code?

Snippet Code


  
Rate this page :
  [ 0 votes]

Use this php code to find and replace a string. Here, "World" string is found and replaced with "Hscripts" in "Hello world" String.

<?php $str="Hello World"; $which_str="World"; $rep_str="Hscripts"; echo str_replace("$which_str", "$rep_str", "$str"); // outputs Hello Hscripts ?>

Tags


Ask Questions

Ask Question