Search and replace on a string
This example shows how to search and replace on a string , this uses php's built in str_replace function . The basic syntax of the str_replace function is
str_replace(search string , replacement string , string);
Here is an example where we wish to change part of a string from asp to php
Code :
<?php
//using str_replace in php
//our message
$msg = "this site has a lot of 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>";
?>
Example :
Original message : this site has a lot of asp code on it
New message : this site has a lot of php code on it