Home | Scripts | Tutorials | Books | Hosting | Forums | Links|

Navigation:

Home
Source code
Tutorials
RSS feeds
Articles
Books
Software
Downloads
Hosting
manuals
Forums
Script directory
Training
Our Links

ADD TO Progged Progged
ADD TO DEL.ICIO.US Del.icio.
ADD TO DIGG Digg
ADD TO FURL Furl
ADD TO NEWSVINE Newsvine
ADD TO NETSCAPE Netscape
ADD TO REDDIT Reddit
ADD TO STUMBLEUPON StumbleUpon
ADD TO TECHNORATI FAVORITES Technorati
ADD TO SQUIDOO Squidoo
ADD TO WINDOWS LIVE Windows Live
ADD TO YAHOO MYWEB Yahoo MyWeb
ADD TO ASK Ask
ADD TO GOOGLE Google
ADD TO MAGNOLIA Magnolia
ADD TO SPURL Spurl



 
 

SPONSORS



 
 

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