当前位置: 首页>>代码示例>>PHP>>正文


PHP html2text类代码示例

本文整理汇总了PHP中html2text的典型用法代码示例。如果您正苦于以下问题:PHP html2text类的具体用法?PHP html2text怎么用?PHP html2text使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了html2text类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: sl_send_email

function sl_send_email($to, $subject, $html, $plain = null, $attachment = null)
{
    if (empty($to)) {
        return false;
    }
    $hash = md5(date('r', time()));
    $headers['From'] = 'The LoveMachine <love@sendlove.us>';
    $headers['To'] = $to;
    if (!empty($html)) {
        if (empty($plain)) {
            $h2t = new html2text($html, 75);
            $plain = $h2t->convert();
        }
        $headers["Content-Type"] = "multipart/alternative; boundary=\"PHP-alt-{$hash}\"";
        $body = "\n--PHP-alt-{$hash}\nContent-Type: text/plain; charset=\"utf-8\"\nContent-Transfer-Encoding: 7bit\n\n" . $plain . "\n\n--PHP-alt-{$hash}\nContent-Type: text/html; charset=\"utf-8\"\nContent-Transfer-Encoding: 7bit\n\n" . $html . "\n\n--PHP-alt-{$hash}--";
        if ($attachment != null && !empty($attachment['name']) && !empty($attachment['content'])) {
            $headers["Content-Type"] = "multipart/mixed; boundary=\"PHP-mixed-{$hash}\"";
            //encode it with MIME base64,
            //and split it into smaller chunks
            $attachmentContent = chunk_split(base64_encode($attachment['content']));
            $body = "\n--PHP-mixed-{$hash}\nContent-Type: multipart/alternative; boundary=\"PHP-alt-{$hash}\"\n\n" . $body . "\n--PHP-mixed-{$hash}  \nContent-Type: {$attachment['type']}; name=\"{$attachment['name']}\"  \nContent-Transfer-Encoding: base64  \nContent-Disposition: attachment  \n\n{$attachmentContent}\n--PHP-mixed-{$hash}-- \n";
        }
    } else {
        $body = $plain;
    }
    send_authmail(array('sender' => 'authuser', 'server' => 'gmail-ssl'), $to, $subject, $body, $headers);
    return true;
}
开发者ID:highfidelity,项目名称:love,代码行数:28,代码来源:send_email.php

示例2: test_html2text

 /**
  * @dataProvider data_html2text
  */
 function test_html2text($title, $in, $out)
 {
     $ht = new html2text(null, false, false);
     $ht->set_html($in);
     $res = $ht->get_text();
     $this->assertEquals($out, $res, $title);
 }
开发者ID:netcon-source,项目名称:roundcubemail,代码行数:10,代码来源:HtmlToText.php

示例3: html2plaintext

function html2plaintext($text, $texthtml0, $wrap)
{
    global $opt, $smiley;
    if ($texthtml0) {
        $text = str_replace(['<p>', "\n", "\r"], '', $text);
        $text = str_replace(['<br />', '</p>'], "\n", $text);
        $text = html_entity_decode($text, ENT_COMPAT, 'UTF-8');
    } else {
        // convert smilies ...
        $countSmileyImage = count($smiley['image']);
        for ($n = 0; $n < $countSmileyImage; $n++) {
            $text = mb_ereg_replace("<img [^>]*?src=[^>]+?" . str_replace('.', '\\.', $smiley['file'][$n]) . "[^>]+?>", "[s![" . $smiley['text'][$n] . "]!s]", $text);
            // the [s[ ]s] is needed to protect the spaces around the smileys
        }
        $h2t = new html2text($text);
        $h2t->set_base_url($opt['page']['default_absolute_url']);
        $h2t->width = $wrap;
        $text = $h2t->get_text();
        $text = str_replace(['[s![', ']!s]'], '', $text);
        // remove e.g. trailing \n created from </p> by html2text
        while (substr($text, -2) == "\n\n") {
            $text = substr($text, 0, strlen($text) - 1);
        }
    }
    return $text;
}
开发者ID:kratenko,项目名称:oc-server3,代码行数:26,代码来源:edithelper.inc.php

示例4: convert

 public function convert()
 {
     require_once AK_VENDOR_DIR . DS . 'TextParsers' . DS . 'html2text.php';
     $Converter = new html2text(true, 0, false);
     $markdown = str_replace('__AK:AMP__', '&', $Converter->load_string(str_replace('&', '__AK:AMP__', $this->source)));
     require_once AK_VENDOR_DIR . DS . 'TextParsers' . DS . 'smartypants.php';
     $Smartypants = new SmartyPantsTypographer_Parser();
     $markdown = Ak::html_entity_decode(strip_tags($Smartypants->transform($markdown)));
     return trim($this->_simplifyMarkdown($markdown));
 }
开发者ID:joeymetal,项目名称:v1,代码行数:10,代码来源:AkHtmlToText.php

示例5: test_html2text

 function test_html2text()
 {
     $data = array(0 => array('title' => 'Test entry', 'in' => '', 'out' => ''), 1 => array('title' => 'Basic HTML entities', 'in' => '&quot;&amp;', 'out' => '"&'), 2 => array('title' => 'HTML entity string', 'in' => '&amp;quot;', 'out' => '&quot;'), 3 => array('title' => 'HTML entity in STRONG tag', 'in' => '<strong>&#347;</strong>', 'out' => 'Ś'), 4 => array('title' => 'STRONG tag to upper-case conversion', 'in' => '<strong>ś</strong>', 'out' => 'Ś'), 5 => array('title' => 'STRONG inside B tag', 'in' => '<b><strong>&#347;</strong></b>', 'out' => 'Ś'));
     $ht = new html2text(null, false, false);
     foreach ($data as $idx => $item) {
         $ht->set_html($item['in']);
         $res = $ht->get_text();
         $this->assertEqual($item['out'], $res, $item['title'] . "({$idx})");
     }
 }
开发者ID:npk,项目名称:roundcubemail,代码行数:10,代码来源:html_to_text.php

示例6: html2plaintext

function html2plaintext($text, $texthtml0)
{
    global $opt, $absolute_server_URI;
    if ($texthtml0) {
        $text = str_replace(array('<p>', "\n", "\r"), '', $text);
        $text = str_replace(array('<br />', '</p>'), "\n", $text);
        $text = html_entity_decode($text, ENT_COMPAT, 'UTF-8');
    } else {
        $h2t = new html2text($text);
        $h2t->set_base_url(isset($opt['page']['absolute_url']) ? $opt['page']['absolute_url'] : $absolute_server_URI);
        $text = $h2t->get_text();
        // remove e.g. trailing \n created from </p> by html2text
        while (substr($text, -2) == "\n\n") {
            $text = substr($text, 0, strlen($text) - 1);
        }
    }
    return $text;
}
开发者ID:harrieklomp,项目名称:oc-server3,代码行数:18,代码来源:edithelper.inc.php

示例7: htmlmail

function htmlmail($to, $subject, $htmlmsg)
{
    require_once 'class.html2text.php';
    $boundary = 'Msg_Boundary--';
    $htmltype = 'text/html; charset="iso-8859-1"';
    $plaintype = str_replace('html', 'plain', $htmltype);
    if (stripos($htmlmsg, '<html') === FALSE) {
        $htmlmsg = "<html>{$htmlmsg}</html>";
    }
    $h2t = new html2text($htmlmsg);
    $plain = $h2t->get_text();
    while (stripos($plain, $boundary) + stripos($htmlmsg, $boundary) > 0) {
        $boundary .= rand();
    }
    // prevent malicious hacking
    $msg = <<<EOF
If you see this message, you may need a newer email program.
--{$boundary}
Content-Type: {$plaintype}
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

{$plain}
--{$boundary}
Mime-Version: 1.0
Content-Type: {$htmltype}
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

{$htmlmsg}
--{$boundary}--
EOF;
    $hdrs = array('From' => 'rC4 <' . SYS_EMAIL . '>', 'Return-Path' => SYS_EMAIL, 'Errors-To' => SYS_EMAIL, 'Content-Type' => "multipart/alternative; boundary=\"{$boundary}\"");
    $smhdrs = '';
    foreach ($hdrs as $key => $value) {
        $smhdrs .= "{$key}: {$value}\n";
    }
    $smhdrs = substr($smhdrs, 0, strlen($smhdrs) - strlen("\n"));
    // omit final EOL
    mail($to, $subject, $msg, $smhdrs, '-f' . SYS_EMAIL);
}
开发者ID:maduhu,项目名称:rCredits,代码行数:41,代码来源:forward.php

示例8:

 /**
  * Override parent function to make links unique
  * @see html2text::_build_link_list()
  */
 function _build_link_list($link, $display)
 {
     // If links already exists, return its existing reference
     if (array_key_exists($link, $this->links)) {
         return $display . ' [' . $this->links[$link] . ']';
     } else {
         $result = parent::_build_link_list($link, $display);
         preg_match('/\\[(\\d+)\\]$/', $result, $m);
         $reference = $m[1];
         $this->links[$link] = $reference;
         return $result;
     }
 }
开发者ID:stephankellermayr,项目名称:newsletter,代码行数:17,代码来源:Builtin.php

示例9: _ff_getListField_gettopic

function _ff_getListField_gettopic($fieldname, $fieldvalue, $A, $icon_arr)
{
    global $_CONF, $_USER, $_TABLES, $LANG_ADMIN, $LANG04, $LANG28, $_IMAGE_TYPE;
    global $_FF_CONF, $_SYSTEM, $LANG_GF02, $LANG_GF03;
    USES_lib_html2text();
    $dt = new Date('now', $_USER['tzid']);
    $retval = '';
    switch ($fieldname) {
        case 'author':
            $retval = $A['name'];
            break;
        case 'date':
            $dt->setTimestamp($fieldvalue);
            $retval = $dt->format($_FF_CONF['default_Datetime_format'], true);
            break;
        case 'lastupdated':
            $dt->setTimestamp($fieldvalue);
            $retval = $dt->format($_FF_CONF['default_Datetime_format'], true);
            break;
        case 'subject':
            $testText = FF_formatTextBlock($A['comment'], 'text', 'text', $A['status']);
            $testText = strip_tags($testText);
            $html2txt = new html2text($testText, false);
            $testText = trim($html2txt->get_text());
            $lastpostinfogll = htmlspecialchars(preg_replace('#\\r?\\n#', '<br>', strip_tags(substr($testText, 0, $_FF_CONF['contentinfo_numchars']) . '...')), ENT_QUOTES, COM_getEncodingt());
            $retval = '<span class="' . COM_getTooltipStyle() . '" style="text-decoration:none;" title="' . $A['subject'] . '::' . $lastpostinfogll . '">' . $fieldvalue . '</span>';
            break;
        case 'select':
            $retval = '[&nbsp;<a href="#" onclick="insert_topic(\'' . $A['id'] . '\'); return false;">' . $LANG_GF03['select'] . '</a>&nbsp;]';
            break;
        default:
            $retval = $fieldvalue;
            break;
    }
    return $retval;
}
开发者ID:spacequad,项目名称:glfusion,代码行数:36,代码来源:gettopic.php

示例10: first_text_part

 /**
  * Return the first text part of this message
  *
  * @return string Plain text message/part content
  */
 function first_text_part()
 {
     // no message structure, return complete body
     if (empty($this->parts)) {
         return $this->body;
     }
     $out = null;
     // check all message parts
     foreach ($this->mime_parts as $mime_id => $part) {
         $mimetype = strtolower($part->ctype_primary . '/' . $part->ctype_secondary);
         if ($mimetype == 'text/plain') {
             $out = $this->imap->get_message_part($this->uid, $mime_id, $part);
             break;
         } else {
             if ($mimetype == 'text/html') {
                 $html_part = $this->imap->get_message_part($this->uid, $mime_id, $part);
                 // remove special chars encoding
                 $trans = array_flip(get_html_translation_table(HTML_ENTITIES));
                 $html_part = strtr($html_part, $trans);
                 // create instance of html2text class
                 $txt = new html2text($html_part);
                 $out = $txt->get_text();
                 break;
             }
         }
     }
     return $out;
 }
开发者ID:jin255ff,项目名称:company_website,代码行数:33,代码来源:rcube_message.php

示例11: html_to_text

/**
 * Given HTML text, make it into plain text using external function
 *
 * @uses $CFG
 * @param string $html The text to be converted.
 * @return string
 */
function html_to_text($html)
{
    global $CFG;
    require_once $CFG->libdir . '/html2text.php';
    $h2t = new html2text($html);
    $result = $h2t->get_text();
    return $result;
}
开发者ID:JackCanada,项目名称:moodle-hacks,代码行数:15,代码来源:weblib.php

示例12: free_categorizeSave

 public function free_categorizeSave($PostedDatas = null, $category, $ForceCat = 0, $ForceExt = 0)
 {
     include_once dirname(__FILE__) . "/class.html2text.inc";
     $sock = new sockets();
     if (!isset($GLOBALS["uuid"])) {
         $sock = new sockets();
         $GLOBALS["uuid"] = base64_decode($sock->getFrameWork("cmd.php?system-unique-id=yes"));
     }
     $uuid = $GLOBALS["uuid"];
     $f = array();
     $ExtractAllUris = $this->ExtractAllUris($PostedDatas);
     if (count($ExtractAllUris) > 0) {
         while (list($num, $ligne) = each($ExtractAllUris)) {
             $f[] = $num;
         }
         $PostedDatas = null;
     }
     $h2t = new html2text($PostedDatas);
     $h2t->get_text();
     while (list($num, $ligne) = each($h2t->_link_array)) {
         if (trim($ligne) == null) {
             continue;
         }
         $ligne = strtolower($ligne);
         $ligne = str_replace("(whois)", "", $ligne);
         $ligne = str_replace("||", "", $ligne);
         $ligne = str_replace("^", "", $ligne);
         $ligne = trim($ligne);
         if (preg_match("#^([0-9\\.]+):[0-9]+#", $ligne, $re)) {
             $websitesToscan[] = $re[1];
             continue;
         }
         if (strpos(" {$ligne}", "http") == 0) {
             $ligne = "http://{$ligne}";
         }
         $hostname = parse_url($ligne, PHP_URL_HOST);
         if (preg_match("#^www\\.(.+)#", $hostname, $re)) {
             $hostname = $re[1];
         }
         if (preg_match("#^\\.(.+)#", $hostname, $re)) {
             $hostname = $re[1];
         }
         if (preg_match("#^\\*\\.(.+)#", $hostname, $re)) {
             $hostname = $re[1];
         }
         writelogs("{$ligne} = {$hostname}", __FUNCTION__, __FILE__, __LINE__);
         $websitesToscan[] = $ligne;
     }
     $PostedDatas = str_replace("<", "\n<", $PostedDatas);
     $PostedDatas = str_replace(' rel="nofollow"', "", $PostedDatas);
     $PostedDatas = str_replace("\r", "\n", $PostedDatas);
     $PostedDatas = str_replace("https:", "http:", $PostedDatas);
     if ($PostedDatas != null) {
         $f = explode("\n", $PostedDatas);
     }
     if (!is_numeric($ForceExt)) {
         $ForceExt = 0;
     }
     if (!is_numeric($ForceCat)) {
         $ForceCat = 0;
     }
     $ipClass = new IP();
     while (list($num, $www) = each($f)) {
         $www = trim($www);
         if ($www == null) {
             continue;
         }
         if (preg_match("#--------------#", $www)) {
             continue;
         }
         if (preg_match("#No extension#", $www)) {
             continue;
         }
         if (preg_match("#no website#i", $www)) {
             continue;
         }
         if (preg_match("#^analyze\\s+[0-9]+\\s+#", $www)) {
             continue;
         }
         if (preg_match("#(false|true):\\s+(.+?)\\s+already#i", $www, $re)) {
             $www = $re[2];
         }
         writelogs("Scanning {$www}", __FUNCTION__, __FILE__, __LINE__);
         if (preg_match("#^(.+?)\"\\s+#", $www, $re)) {
             $www = $re[1];
         }
         if (preg_match("#^([0-9\\.]+):[0-9]+#", $www, $re)) {
             $www = $re[1];
         }
         $www = str_replace("(whois)", "", $www);
         $www = str_replace("\r", "", $www);
         $www = str_replace("||", "", $www);
         $www = str_replace("^", "", $www);
         $www = trim(strtolower($www));
         if ($ipClass->isValid($www)) {
             $www = ip2long($www) . ".addr";
             $websitesToscan[] = $www;
             continue;
         }
         if ($www == null) {
//.........这里部分代码省略.........
开发者ID:articatech,项目名称:artica,代码行数:101,代码来源:class.mysql.squid.builder.php

示例13: silcc_submit_post

/**
 * Get a blog and add tags from the silcc API
 */
function silcc_submit_post($post_id)
{
    global $wpdb;
    $post_id = (int) $post_id;
    $blog = $wpdb->get_row("SELECT * FROM {$wpdb->posts} WHERE ID = '{$post_id}' ");
    if (!$blog) {
        // it was deleted
        return;
    }
    // This is where we extract the text to tag
    // TODO: Make sure this text is not HTML (To avoid HTML tagging)
    // Include the html to text conversion library
    require dirname(__FILE__) . "/class.html2text.inc";
    $html_text = stripslashes($blog->post_content);
    $html_to_text_class = new html2text($html_text);
    $text_content = $html_to_text_class->get_text();
    $tags = array();
    if (!is_null($text_content)) {
        if (strlen($text_content) > 240) {
            $tags = tagthe_http_get($text_content);
        } else {
            if (strlen($text_content) > 0 && strlen($text_content) < 240) {
                $query_string = '' . urlencode($text_content) . '&';
                $response = silcc_http_get($query_string);
                $clean_response = str_replace('[', '', $response);
                $clean_response = str_replace(']', '', $clean_response);
                $clean_response = str_replace(' ', '', $clean_response);
                $clean_response = str_replace('"', '', $clean_response);
                $tags = explode(',', $clean_response);
            }
        }
    }
    wp_set_post_terms($post_id, $tags);
    if (count($tags) > 0) {
        silcc_update_options(count($tags));
    }
}
开发者ID:ushahidi,项目名称:wp-silcc,代码行数:40,代码来源:wp-silcc.php

示例14: html2text

/**
 * Given HTML, converts and formats it as text
 *
 * @param string $html The html to be formatted
 * @return string The formatted text
 */
function html2text($html)
{
    require_once 'html2text/class.html2text.php';
    $h2t = new html2text($html);
    $h2t->set_base_url(get_config('wwwroot'));
    return $h2t->get_text();
}
开发者ID:Br3nda,项目名称:mahara,代码行数:13,代码来源:web.php

示例15: COM_buildUrl

 // Set page title
 $pagetitle = $story->DisplayElements('title');
 $outputHandle = outputHandler::getInstance();
 $permalink = COM_buildUrl($_CONF['site_url'] . '/article.php?story=' . $story->getSid());
 $outputHandle->addLink('canonical', $permalink);
 if ($story->DisplayElements('trackbackcode') == 0) {
     if ($_CONF['trackback_enabled']) {
         $trackbackurl = TRB_makeTrackbackUrl($story->getSid());
         $outputHandle->addRaw(LB . '<!--' . LB . TRB_trackbackRdf($permalink, $pagetitle, $trackbackurl) . LB . '-->' . LB);
     }
     $pingback = true;
 }
 USES_lib_html2text();
 $metaDesc = $story->DisplayElements('introtext');
 $metaDesc = strip_tags($metaDesc);
 $html2txt = new html2text($metaDesc, false);
 $metaDesc = trim($html2txt->get_text());
 $shortComment = '';
 $metaArray = explode(' ', $metaDesc);
 $wordCount = count($metaArray);
 $lengthCount = 0;
 $tailString = '';
 foreach ($metaArray as $word) {
     $lengthCount = $lengthCount + strlen($word);
     $shortComment .= $word . ' ';
     if ($lengthCount >= 100) {
         $tailString = '...';
         break;
     }
 }
 $metaDesc = trim($shortComment) . $tailString;
开发者ID:NewRoute,项目名称:glfusion,代码行数:31,代码来源:article.php


注:本文中的html2text类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。