0

I'm trying to make a function in admin panel of my project, that will be sending e-mails with some dynamic parameters in format *|folder:function|*. E.g.: I write in text form

Hello, *|USER:FIRSTNAME|*. 
You can *|START-LINKS:ACTIVATE|*activate*|END-LINKS|* your account. 
Also you can *|START-LINKS:UNSUBSCRIBE|*unsubscribe*|END-LINKS|*. 

and want to get

Hello, John.
You can <a href="http://example.com/?do=activate&user_id=useridfromdatabase&unique=4se5dr6ftygyuertcfvgbh">activate</a> your account.
Also you can <a href="http://example.com/?do=unsubscribe&user_id=useridfromdatabase&unique=45r6ftetdf3445656576yt">unsubscribe</a>

But I don't know how I can replace my tags with the data that I needed. Can anybody help me with that?

Azrael
  • 1,094
  • 8
  • 19

2 Answers2

0
$bodytag = str_replace("*|USER:FIRSTNAME|*", "John", "Hello, *|USER:FIRSTNAME|*. 
You can *|START-LINKS:ACTIVATE|*activate*|END-LINKS|* your account. 
Also you can *|START-LINKS:UNSUBSCRIBE|*unsubscribe*|END-LINKS|*.");

This is what you ask for but you have many possibilities str_replace, regular expression or sprintf

http://fr2.php.net/manual/en/function.sprintf.php http://fr2.php.net/manual-lookup.php?pattern=replace&scope=quickref

AMS
  • 439
  • 2
  • 12
0

Use something like

$email_body = str_replace("*|USER:FIRSTNAME|*, $users_name, $email_body");

If you can help it, don't try and be too clever, because when it breaks in two years time, you'll have no idea how to fix it quickly.

If you insist on doing it slightly more cleverly, use this function to get the data between your beginning and end characters and explode() the contents by the : character.

Community
  • 1
  • 1
Prinsig
  • 245
  • 3
  • 9