See this:

What do you think that I create an array of regexp patterns and foreach it, then within foreach I I use preg_split to remove quoted parts of email instead of that loop you see on that page?

If yes, then if a pattern matches and the message is splited I have to break the loop, but preg_split does not return true/false that I can use it in an IF statement to check if it already matches a pattern to break the loop. so how should I break the loop of patterns with preg_split? How to improve the loop of that code block not necessarily preg_split?

Maybe try a callback that returns either the string or boolean?

please give an example that I understand better why you mean by callback?

Just that

In other words, move the preg_split (or whatever) into a function written so that it returns what you want it to return.
Then call that function inside the loop

If this were you, which one do you go with? just keep that loop with preg_match as it is on the link I gave? or you’d re-write it with preg_split with callback as you said?

If it were me, the first thing I would do is try to clean up that chain of "else if"s

That said, the decision is up to you.

If a function is not returning what you need it to it’s time to look for an alternate function or write something custom.

How you’d go to clean up that chain of "else if"s? Can you provide a code example how you’d go to improve it?

Well, you are more familiar with the code than I am so you would know better than I.
eg. I don’t know why there are matches being captured that apparently aren’t being used.

But one thing I might try is consolidating the eight regex ifs into one something like

"/^(-|On|>)*(.*)(Original Message|wrote:|$fromName|$toName|$toEmail|$fromEmail|On)?(.*)(-|wrote:)*/i"

More difficult to read in some ways, but much less lines to read and have processed.

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.