Page 1 of 1

help

Posted: Thu Mar 25, 2010 2:58 am
by slpsrinivas
Hi

I am new to regular expressions please help me in writing this function

Write a function in PHP that will take in 2 parameters: 1) a string of text 2) an array of words to be replaced where the key is the original word and the value is the new word. The function should return the corrected string.

i.e.

Code: Select all

<?php
function cleanString($str, $wordArray) {
...
}
$wordArray = array('cat'=>'dog','bad'=>'good','old'=>'new');
echo cleanString($someString, $wordArray);
?>

Re: help

Posted: Thu Mar 25, 2010 4:32 pm
by Christopher
Check the manual for str_replace(). I think it will work better for this.

http://us.php.net/manual/en/function.str-replace.php