Escaping [ ] characters in message body/footer

Solutions for other advanced phplisters

Escaping [ ] characters in message body/footer

Postby jezdikm » 2:02pm, Fri 12 Oct, 2007

I found an interesting problem today. You know [ ] brackets are used for keywords in PHPList. Eg. [PREFERENCES] or [UNSUBSCRIBE] are substituted with links.

Now my problem. I need to have a text like [-CCC-] in my message body/footer.

When I do this, everything is fine. The only problem is the PERFORMANCE as the php is trying to parse the text between [] and it takes a lot of CPU and slows down the processing.

In fact we usually send about 30.000msgs/hour. With this [-CCC-] text in the message the speed decrease to about 7.000msgs/hour.

My question is: Can I somehow escape the brackets so PHPList won't try to find appropriate keyword?

Thank you,

ps: I can not use &#91 ; entity as I need to have single [ character in the message
Posts: 12
Joined: 3:31pm, Thu 16 Nov, 2006

Postby H2B2 » 5:03pm, Sun 14 Oct, 2007

This issue has been discussed before, e.g.:

Unfortunately, it appears no one has been able to define a clear solution, besides this workaround for HTML messages (apparently not useful in your case):
phpfan wrote:In the HTML version, using the HTML codes for left square bracket (&# 91;) and right square bracket (&# 93;) works.
Posts: 7188
Joined: 1:51am, Wed 15 Mar, 2006

A workaround

Postby maxxxie » 3:42am, Sun 23 Mar, 2008


Since I don't plan to use placeholders, I found a small piece of code in lists/admin/sendemaillib.php and commented it out:

Lines 508-510:
Code: Select all
  ## remove any existing placeholders
  $htmlmessage = eregi_replace("\[[A-Z\. ]+\]","",$htmlmessage);
  $textmessage = eregi_replace("\[[A-Z\. ]+\]","",$textmessage);

Change to:
Code: Select all
  ## remove any existing placeholders
  // $htmlmessage = eregi_replace("\[[A-Z\. ]+\]","",$htmlmessage);
  // $textmessage = eregi_replace("\[[A-Z\. ]+\]","",$textmessage);

This prevents removal of square brackets from the text. I have no idea if this breaks anything, but since I don't use placeholders in my newsletters, it seems like a quick and dirty solution.

phpList newbie
Posts: 1
Joined: 3:38am, Sun 23 Mar, 2008

Postby ohill » 4:25pm, Tue 24 Jun, 2008

I work around this problem adding 2 lines in the sendemailib.php :

Code: Select all
  $transbracket = array("[" => "[", "]" => "]");
  $textmessage = strtr($textmessage, $transbracket);

just after line 510 refering maxxxie's post.

I use HTML entities [ and ] in my newsletters content/footer/template to add brackets :)
phpList newbie
Posts: 3
Joined: 4:14pm, Tue 24 Jun, 2008

try it like this: [[text]text]

Postby ojrokk » 9:45pm, Mon 02 Feb, 2009

try it like this:


works for me...not sure why or if it'll break something.

Return to Advanced Answers, Howtos, Tips & Tricks

Who is online

Users browsing this forum: No registered users and 1 guest