Link to home
Start Free TrialLog in
Avatar of interclubs
interclubs

asked on

Search and Replace Function...

I have an array like such:
$ReplaceTerms = array(
                  'dog' => 'cat',
                  'fire' => 'water'
            );

and I am looking to put together a function that I can pass the array and content to like such:

TransformInput($ReplaceTerms, $content)

The Function would then do a case insensitive search and replace on $content swapping out the text in the array. So 'dog' would become 'cat' and 'fire' would become 'water'

Make any sense?
SOLUTION
Avatar of ddrudik
ddrudik
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You might want to compare type as well, if so change:
        if($val==$term){
to:
        if($val===$term){
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of interclubs
interclubs

ASKER

I'm sorry, my bad, the 2nd piece pass to it ($subjectarray) won't be an array, it will be just straight text...
as in : $testarr='foo dog fire foo dog';
Then you should be OK with the function I posted above.  It tested out OK.  Best, ~Ray
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks for the question and the points.