示例#1
0
文件: str.php 项目: NatWeiss/JankyPHP
 static function str2metadesc($txt)
 {
     $txt = str::condenseHtmlChars($txt, ' ');
     $txt = str::condenseTags($txt, ' ');
     $txt = str_replace(array('"', ' .'), array("'", '.'), $txt);
     $txt = trim(str::condenseWhitespace($txt));
     if (strlen($txt) > 320) {
         $txt = substr($txt, 0, 317) . '...';
     }
     return $txt;
 }
示例#2
0
 private static function bodies2plain($bodies, $msgType)
 {
     $ret = '';
     // clear html if both html and plain exist
     if ($msgType == 'multipart/alternative') {
         foreach ($bodies as $k => $i) {
             if ($i['type'] == 'text/plain') {
                 $hasPlain = true;
             }
         }
         if ($hasPlain) {
             foreach ($bodies as $k => $i) {
                 if ($i['type'] == 'text/html') {
                     unset($bodies[$k]);
                 }
             }
         }
     }
     // condense bodies
     foreach ($bodies as $part) {
         // strip "=" at end of line
         if ($part['encoding'] == 'quoted-printable') {
             $part['body'] = quoted_printable_decode($part['body']);
         }
         // convert html to plain text
         if ($part['type'] == 'text/html') {
             // get html body element
             $txt = str::between($part['body'], '<body>', '</body>', $pos = 0, true);
             // improper html? just use the whole body part
             if (!strlen($txt)) {
                 $txt = $part['body'];
             }
             // clean up
             $txt = str::br2nl($txt);
             $txt = trim(str::condenseTags($txt));
             $txt = preg_replace('{[ \\t]+}', ' ', $txt);
             $ret .= $txt;
         } else {
             $ret .= $part['body'];
         }
     }
     return $ret;
 }