Forum Moderators: coopster

Message Too Old, No Replies

Converting BR to new lines

         

asantos

6:27 pm on Jun 22, 2006 (gmt 0)

10+ Year Member



Hi
im developing a membership system, which emails new users some info. THAT info has HTML on it (im using phpMailer to handle the email sending).

With phpMailer i can do this:
$mail->Body = $html;
$mail->AltBody = plain($html);

So, every member that has an email-client that supports HTML, will get the $html, and those that use an email client that handle text-only emails will get the plain($html).

My problem is at the plain() function. I need to accomplish this:
* Replace the BR tag with newlines (\n) so that all new lines show in text-only email clients as well.

Further considerations:
* The BR tag can be <br>, <br />, <br/>, etc.. so ill need a proper preg_replace there

This is my plain() function so far:
function plain($data) {
return strip_tags($data);
}

Thanks in advance,
Andres

eelixduppy

6:31 pm on Jun 22, 2006 (gmt 0)



strip_tags [us3.php.net] will also remove the break tags.

You can do something like this:


function plain($text)
{
$breaks = array("<br>","<br/>","<br />","<BR>","<BR/>","<BR />");
$no_break = [url=http://us3.php.net/manual/en/function.str-replace.php]str_replace[/url]($breaks,"\n",$text);
return strip_tags($no_break);
}

asantos

9:09 pm on Jun 22, 2006 (gmt 0)

10+ Year Member



eelixduppy, actually i found a better way:

$txt = preg_replace('/<br\s*\/?\s*>/Ui', "\n", $txt);

And THEN the strip_tags(). Thanks.