Mega Code Archive

 
Categories / Php / Code Snippets
 

This example shows how to search and replace on a string

<?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>"; ?>