johnnyk Posted July 28, 2006 Share Posted July 28, 2006 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? Quote Link to comment https://forums.phpfreaks.com/topic/15906-wordwrap-html/ Share on other sites More sharing options...
Ninjakreborn Posted July 28, 2006 Share Posted July 28, 2006 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 Link to comment https://forums.phpfreaks.com/topic/15906-wordwrap-html/#findComment-65468 Share on other sites More sharing options...
Barand Posted July 29, 2006 Share Posted July 29, 2006 This should work[code]<?phpfunction 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] Quote Link to comment https://forums.phpfreaks.com/topic/15906-wordwrap-html/#findComment-65562 Share on other sites More sharing options...
johnnyk Posted July 30, 2006 Author Share Posted July 30, 2006 [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? Quote Link to comment https://forums.phpfreaks.com/topic/15906-wordwrap-html/#findComment-65712 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.