Jump to content

wordwrap() html


johnnyk

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?
Link to comment
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]
Link to comment
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?
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.