PHP str_replace

General discussions related to php

Moderators: macek, egami, gesf

New php-forum User
New php-forum User
Posts: 1
Joined: Sat Aug 18, 2012 6:39 am

PHP str_replace

Postby Girl » Sat Aug 18, 2012 6:41 am

Hi people. I need help.
I want to use str_replace function a few times.
THe problem is this: for example i have two words: "table" and "house".
I want to replace one word's letters by other one, like:

I have letters, when I click on "t", "house"-becomes "touse". But when after it I click "a", it bcomes "hause", not "tause", means it doesn't keep the previous change.
I know I must keep that change somehow, but I don know how.
Please reply if you know.

php-forum Fan User
php-forum Fan User
Posts: 578
Joined: Fri Aug 05, 2011 9:53 am

Re: PHP str_replace

Postby NigelRen » Sun Aug 19, 2012 12:09 am

The simplest way of doing this is having a variable with the previous value in it. So if your working with $word then $prevWord would be the previous version of it. Before making any change to $word - simply use $prevWord = $word;. Then each change would actually be something like...

Code: Select all


New php-forum User
New php-forum User
Posts: 35
Joined: Mon Aug 20, 2012 10:27 pm
Location: Ernakulam

Re: PHP str_replace

Postby Acesystech » Mon Aug 20, 2012 11:39 pm

The str_replace() function replaces some characters with some other characters in a string.




find:-Required. Specifies the value to find
replace:- Required. Specifies the value to replace the value in find
string:-Required. Specifies the string to be searched
count:-Optional. A variable that counts the number of replacements

Return to “PHP General”

Who is online

Users browsing this forum: No registered users and 5 guests