Search and replace on a string

This example uses the str_replace function to replace some text in a string with another piece of text.

//using str_replace in php
//our message
$msg = “this site has  asp code on it”;
//the string we want added
$add_this = “php”;
//replace the asp with php
$new_message = str_replace(“asp” , $add_this , $msg);
//display original message then new message
echo “Original message : $msg <br>”;
echo “New message : $new_message <br>”;


Please enter your comment!
Please enter your name here