Jump to content

Archived

This topic is now archived and is closed to further replies.

johnnyk

wordwrap() html

Recommended Posts

How do you wordwrap html? I have a crappy little mailing list thing I made that sends an html email. Whenever I try to wordwrap() $message with "<.br />\n", the email won't send (and I'm assuming that's becuase html tags are getting broken up with "<.br />\n", which is bad). Any suggestions?

And when's phpfreaks gonna fix the <.br /> problem?

Share this post


Link to post
Share on other sites
You shouldn't need to wordwrap those, just take a few extra seconds to add in br tags.  Be careful with html emails it ALWAYS double emails.  one with html and one without I believe is what the manual says

Share this post


Link to post
Share on other sites
This should work

[code]<?php
function htmlwordwrap ($txt, $n, $break="\n", $split=0) {
$res = '';
$pos = $k = $intag = 0;
$L = strlen($txt);
while ($pos < $L) {
                $ch = $txt{$pos};
$res .= $ch;
switch ($ch) {
case '<': $intag = 1;
break;
case '>': $intag = 0;    
break;
case ' ': if (!$intag) {
$x = $split ? 0 : 5;
if ($n < $k+$x) {
$res .= $break;
$k = 0;
}
else $k++;
  }
  break;
default: if ($split) {
if (!$intag) {
if ($n < $k) {
$res .= $break;
$k = 0;
}
else $k++;
}
}
else {
if (!$intag) $k++;
}
}
$pos++;
}
return $res;
}

echo htmlwordwrap($html,40, "<br/>\n", 0);

?>
[/code]

Share this post


Link to post
Share on other sites
[quote author=businessman332211 link=topic=102186.msg405452#msg405452 date=1154125657]
You shouldn't need to wordwrap those, just take a few extra seconds to add in br tags.  Be careful with html emails it ALWAYS double emails.  one with html and one without I believe is what the manual says
[/quote]
Where does it say that?

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.