PHP find pattern and replace script

Web, Mobile & Software Dev Web Development Posted 1 year ago

Fixed Price

Delivery by September 2, 2013

$10.00

Budget

Details

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

Skills Required:

Client Activity on this Job

Last Viewed: 1 year ago

Applicants: 2

Hired: 1


About the Client

(4.96) 21 reviews

Chile
Santiago 04:38 AM

26 Jobs Posted
93% Hire Rate, 1 Open Job

Over $10,000 Total Spent
26 Hires, 0 Active

$15.37/hr Avg Hourly Rate Paid
958 Hours

Member Since Mar 31, 2012