Simplifying format_mail

Peter Cruickshank <list-UnZd7gj/[email protected]> Thu, 11 Dec 2003 19:54:46 +0000
Newsgroups gmane.comp.cms.phpslash.devel
Message-ID <[email protected]>
Just wondering if it would make sense to revise format_mail() to take 
advantage of php4's functionality - moving from:

function format_mail($str, $char_len, $scrub) {    //BEGIN FUNCTION

   if ($scrub) {               //Open if Scrub

      $str = stripslashes($str);

      // lh: Hopefully this is the short replacement
      $str = eregi_replace('<(/?)(a|b|br|i|p)+[^>]*>', "", $str);
      $str = eregi_replace("\n|\r|[[:space:]]+|10|13|&#....;", " ", $str);

      $str = stripslashes($str);
   }               //Close if Scrub
   while(strlen($str) != 0) {               //Open While
      if (strlen($str) > $char_len)  {
         $len = strrpos(substr($str, 0, $char_len - 1), " ");
      } else {
          $len = 0;
      }
      // in case of no spaces
      if(!$len) {
         $len = $char_len - 1;
      }
      $str_out .= substr($str, 0, $len) . "\n";
      $str = ltrim(substr($str, $len, strlen($str)));
   }              //End While
   return $str_out;



To:

   function format_mail($str, $char_len=76, $scrub=false) {
      if ($scrub) {
         $str = strip_tags($str);
      }
      $str_out = wordwrap($str, $char_len, "\n", true);
      return $str_out;
   }

The current version seems to let some tags through (eg <table> or <div> - is 
that deliberate?)

There must be some subtelty I'm missing? 

Peter


-------------------------------------------------------
This SF.net email is sponsored by: SF.net Giveback Program.
Does SourceForge.net help you be more productive?  Does it
help you create better code?  SHARE THE LOVE, and help us help
YOU!  Click Here: http://sourceforge.net/donate/