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


PHP Horde_String::trimUtf8Bom方法代码示例

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


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

示例1: parsevCalendar

 /**
  * Parses a string containing vCalendar data.
  *
  * @todo This method doesn't work well at all, if $base is VCARD.
  *
  * @param string $text     The data to parse.
  * @param string $base     The type of the base object.
  * @param boolean $clear   If true clears this object before parsing.
  *
  * @return boolean  True on successful import, false otherwise.
  * @throws Horde_Icalendar_Exception
  */
 public function parsevCalendar($text, $base = 'VCALENDAR', $clear = true)
 {
     if ($clear) {
         $this->clear();
     }
     $text = Horde_String::trimUtf8Bom($text);
     if (preg_match('/^BEGIN:' . $base . '(.*)^END:' . $base . '/ism', $text, $matches)) {
         $container = true;
         $vCal = $matches[1];
     } else {
         // Text isn't enclosed in BEGIN:VCALENDAR
         // .. END:VCALENDAR. We'll try to parse it anyway.
         $container = false;
         $vCal = $text;
     }
     $vCal = trim($vCal);
     // Extract all subcomponents.
     $matches = $components = null;
     if (preg_match_all('/^BEGIN:(.*)\\s*?(\\r\\n|\\r|\\n)(.*)^END:\\1\\s*?/Uims', $vCal, $components)) {
         foreach ($components[0] as $key => $data) {
             // Remove from the vCalendar data.
             $vCal = str_replace($data, '', $vCal);
         }
     } elseif (!$container) {
         return false;
     }
     // Unfold "quoted printable" folded lines like:
     //  BODY;ENCODING=QUOTED-PRINTABLE:=
     //  another=20line=
     //  last=20line
     while (preg_match_all('/^([^:]+;\\s*(ENCODING=)?QUOTED-PRINTABLE(.*=\\r?\\n)+(.*[^=])?(\\r?\\n|$))/mU', $vCal, $matches)) {
         foreach ($matches[1] as $s) {
             $r = preg_replace('/=\\r?\\n/', '', $s);
             $vCal = str_replace($s, $r, $vCal);
         }
     }
     // Unfold any folded lines.
     $vCal = preg_replace('/[\\r\\n]+[ \\t]/', '', $vCal);
     // Parse the remaining attributes.
     if (preg_match_all('/^((?:[^":]+|(?:"[^"]*")+)*):([^\\r\\n]*)\\r?$/m', $vCal, $matches)) {
         foreach ($matches[0] as $attribute) {
             preg_match('/([^;^:]*)((;(?:[^":]+|(?:"[^"]*")+)*)?):([^\\r\\n]*)[\\r\\n]*/', $attribute, $parts);
             $tag = trim(preg_replace('/^.*\\./', '', Horde_String::upper($parts[1])));
             $value = $parts[4];
             $params = array();
             // Parse parameters.
             if (!empty($parts[2])) {
                 preg_match_all('/;(([^;=]*)(=("[^"]*"|[^;]*))?)/', $parts[2], $param_parts);
                 foreach ($param_parts[2] as $key => $paramName) {
                     $paramName = Horde_String::upper($paramName);
                     $paramValue = $param_parts[4][$key];
                     if ($paramName == 'TYPE') {
                         $paramValue = preg_split('/(?<!\\\\),/', $paramValue);
                         if (count($paramValue) == 1) {
                             $paramValue = $paramValue[0];
                         }
                     }
                     if (is_string($paramValue)) {
                         if (preg_match('/"([^"]*)"/', $paramValue, $parts)) {
                             $paramValue = $parts[1];
                         }
                     } else {
                         foreach ($paramValue as $k => $tmp) {
                             if (preg_match('/"([^"]*)"/', $tmp, $parts)) {
                                 $paramValue[$k] = $parts[1];
                             }
                         }
                     }
                     if (isset($params[$paramName])) {
                         if (is_array($params[$paramName])) {
                             $params[$paramName][] = $paramValue;
                         } else {
                             $params[$paramName] = array($params[$paramName], $paramValue);
                         }
                     } else {
                         $params[$paramName] = $paramValue;
                     }
                 }
             }
             // Charset and encoding handling.
             if (isset($params['ENCODING']) && Horde_String::upper($params['ENCODING']) == 'QUOTED-PRINTABLE' || isset($params['QUOTED-PRINTABLE'])) {
                 $value = quoted_printable_decode($value);
                 if (isset($params['CHARSET'])) {
                     $value = Horde_String::convertCharset($value, $params['CHARSET'], 'UTF-8');
                 }
             } elseif (isset($params['CHARSET'])) {
                 $value = Horde_String::convertCharset($value, $params['CHARSET'], 'UTF-8');
             }
//.........这里部分代码省略.........
开发者ID:kossamums,项目名称:horde,代码行数:101,代码来源:Icalendar.php


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