php find replace -
this more of "best practices" question.
i have few email templates, have several tags need find , replace.
for example:
dear [[customername]], blah blah blah blah, , more blah. invoice.... ---------------------------------------------------------- order status: [[orderstatus]] order number: [[orderid]] date ordered: [[dateordered]] payment method: [[paymentmethod]] billing statement: [[billingstatement]]
anyway, have several of these tags inside double brackets. i'm using simple: $text = str_replace($oldword , $newword , $text);
i'm sure normal way this, curious if has thoughts on different way. otherwise, i'll stick i'm doing.
you can use arrays str_replace:
$oldwords = array('[[customername]]', '[[orderstatus]]' ); $newwords = array($customername, $orderstatus ); $newtext = str_replace($oldwords , $newwords , $text);
you use preg_replace array
$oldwords = array('/\[\[customername\]\]/', '/\[\[orderstatus\]\]/' ); $newwords = array($customername, $orderstatus ); $newtext = preg_replace($oldwords , $newwords , $text);
Comments
Post a Comment