php search and replace

Posted by Dave on Stack Overflow See other posts from Stack Overflow or by Dave
Published on 2010-05-06T17:25:13Z Indexed on 2010/05/06 17:28 UTC
Read the original article Hit count: 250

Filed under:

I am trying to create a database field merge into a document (rtf) using php

i.e if I have a document that starts

Dear Sir,

Customer Name: [customer_name], Date of order: [order_date]

After retrieving the appropriate database record I can use a simple search and replace to insert the database field into the right place.

So far so good.

I would however like to have a little more control over the data before it is replaced. For example I may wish to Title Case it, or convert a delimited string into a list with carriage returns.

I would therefore like to be able to add extra formatting commands to the field to be replaced. e.g.

Dear Sir,

Customer Name: [customer_name, TC], Date of order: [order_date, Y/M/D]

There may be more than one formatting command per field.

Is there a way that I can now search for these strings? The format of the strings is not set in stone, so if I have to change the format then I can.

Any suggestions appreciated.

© Stack Overflow or respective owner

Related posts about php