help

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
slpsrinivas
Forum Newbie
Posts: 1
Joined: Thu Mar 25, 2010 2:54 am

help

Post 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);
?>
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: help

Post 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
(#10850)
Post Reply