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


PHP Horde_String::regexMatch方法代码示例

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


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

示例1: _reformat

 /**
  * Reformats the input string, where the string is 'format=flowed' plain
  * text as described in RFC 2646.
  *
  * @param boolean $toflowed  Convert to flowed?
  * @param boolean $quote     Add level of quoting to each line?
  * @param boolean $wrap      Wrap unquoted lines?
  */
 protected function _reformat($toflowed, $quote, $wrap = true)
 {
     $format_type = implode('|', array($toflowed, $quote));
     if ($format_type == $this->_formattype) {
         return;
     }
     $this->_output = array();
     $this->_formattype = $format_type;
     /* Set variables used in regexps. */
     $delsp = $toflowed && $this->_delsp ? 1 : 0;
     $opt = $this->_optlength - 1 - $delsp;
     /* Process message line by line. */
     $text = preg_split("/\r?\n/", $this->_text);
     $text_count = count($text) - 1;
     $skip = 0;
     reset($text);
     while (list($no, $line) = each($text)) {
         if ($skip) {
             --$skip;
             continue;
         }
         /* Per RFC 2646 [4.3], the 'Usenet Signature Convention' line
          * (DASH DASH SP) is not considered flowed.  Watch for this when
          * dealing with potentially flowed lines. */
         /* The next three steps come from RFC 2646 [4.2]. */
         /* STEP 1: Determine quote level for line. */
         if ($num_quotes = $this->_numquotes($line)) {
             $line = substr($line, $num_quotes);
         }
         /* Only combine lines if we are converting to flowed or if the
          * current line is quoted. */
         if (!$toflowed || $num_quotes) {
             /* STEP 2: Remove space stuffing from line. */
             $line = $this->_unstuff($line);
             /* STEP 3: Should we interpret this line as flowed?
              * While line is flowed (not empty and there is a space
              * at the end of the line), and there is a next line, and the
              * next line has the same quote depth, add to the current
              * line. A line is not flowed if it is a signature line. */
             if ($line != '-- ') {
                 while (!empty($line) && substr($line, -1) == ' ' && $text_count != $no && $this->_numquotes($text[$no + 1]) == $num_quotes) {
                     /* If DelSp is yes and this is flowed input, we need to
                      * remove the trailing space. */
                     if (!$toflowed && $this->_delsp) {
                         $line = substr($line, 0, -1);
                     }
                     $line .= $this->_unstuff(substr($text[++$no], $num_quotes));
                     ++$skip;
                 }
             }
         }
         /* Ensure line is fixed, since we already joined all flowed
          * lines. Remove all trailing ' ' from the line. */
         if ($line != '-- ') {
             $line = rtrim($line);
         }
         /* Increment quote depth if we're quoting. */
         if ($quote) {
             $num_quotes++;
         }
         /* The quote prefix for the line. */
         $quotestr = str_repeat('>', $num_quotes);
         if (empty($line)) {
             /* Line is empty. */
             $this->_output[] = array('text' => $quotestr, 'level' => $num_quotes);
         } elseif (!$wrap && !$num_quotes || empty($this->_maxlength) || Horde_String::length($line, $this->_charset) + $num_quotes <= $this->_maxlength) {
             /* Line does not require rewrapping. */
             $this->_output[] = array('text' => $quotestr . $this->_stuff($line, $num_quotes, $toflowed), 'level' => $num_quotes);
         } else {
             $min = $num_quotes + 1;
             /* Rewrap this paragraph. */
             while ($line) {
                 /* Stuff and re-quote the line. */
                 $line = $quotestr . $this->_stuff($line, $num_quotes, $toflowed);
                 $line_length = Horde_String::length($line, $this->_charset);
                 if ($line_length <= $this->_optlength) {
                     /* Remaining section of line is short enough. */
                     $this->_output[] = array('text' => $line, 'level' => $num_quotes);
                     break;
                 } else {
                     $regex = array();
                     if ($min <= $opt) {
                         $regex[] = '^(.{' . $min . ',' . $opt . '}) (.*)';
                     }
                     if ($min <= $this->_maxlength) {
                         $regex[] = '^(.{' . $min . ',' . $this->_maxlength . '}) (.*)';
                     }
                     $regex[] = '^(.{' . $min . ',})? (.*)';
                     if ($m = Horde_String::regexMatch($line, $regex, $this->_charset)) {
                         /* We need to wrap text at a certain number of
                          * *characters*, not a certain number of *bytes*;
                          * thus the need for a multibyte capable regex.
//.........这里部分代码省略.........
开发者ID:raz0rsdge,项目名称:horde,代码行数:101,代码来源:Flowed.php


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