PHP find pattern and replace script

PHP find pattern and replace script

Closed - This job posting has been filled.

Job Description

JOB DESCRIPTION:

I have strings of text where I want to find certain patterns and replace these patterns accordingly. I will add my own logic afterwards, so what I need now is just the basic find & replace implementation. If you are good with regular expressions this should be a piece of cake.

The pattern that I'm looking for is something like this: [keyword, parameter], there can be spaces in between like [ keyword , parameter].

For example see this text string:

$content = '<h1>this is content</h1> welcome [user,name] how are you? how is [user, bestFriend]. Did you go to [field, sómeInternationalFíéld] after you visited [ field , someCity ]? here is the weather report: [report, someReportName]';

What I need, in pseudo-code is for you to create a function that does the following:

1- find all patterns [ string that could contain numbers, spaces and the international characters á, é, í, ó, ú and ñ , string that could contain numbers, spaces and the international characters á, é, í, ó, ú and ñ]

examples: [user,name], [user, best Friend], [field, sómeInternational Fíéldñññ]

2- for each found pattern, apply the following transformation:
2.1-change to lowercase
2.2-remove all spaces, tabs
2.3-change á, é, í, ó, ú to: a, e, i, o, u

3- I will do DB searches using "keyword" and "parameter" (remember: [keyword,parameter]), you can just assume a result:

//$result = some DB_search_I_will_do($keyword, $parameter);
you just save this as $result = $keyword.'-'.$parameter;

replace all found patters by their correspoding "$result" variable.

So for example, $content will end up like this after running this function in it (THIS IS YOUR TEST CASE!):

$content = '<h1>this is content</h1> welcome [user,name] how are you? how is [user, bestFriend]. Did you go to [field, sómeInternationalFíéld] after you visited [ field , someCity ]? here is the weather report: [report, someReportName]';
$new_content = your_magic_function($content);
echo $new_content;

//should be this:
// <h1>this is content</h1> welcome user-name how are you? how is user-bestfriend. Did you go to field-someinternationalfield after you visited field-somecity? here is the weather report: report-somereportname

that's it!

JOB TERMS:

-I need this ASAP, you need to be able to begin right now.

-payment and 5 star review after completion and successfully passing the test.

-I don't have time to do Skype interviews or such, the instructions need to be clear.

-NO AGENCIES