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


PHP SimplePie_Misc::utf8_bad_replace方法代码示例

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


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

示例1: init


//.........这里部分代码省略.........
            } else {
                if (!empty($headers['content-type']) && preg_match('/charset\\s*=\\s*([^;]*)/i', $headers['content-type'], $charset)) {
                    $encoding = $charset[1];
                } else {
                    if (preg_match('/^<\\?xml(.*)?>/msiU', $data, $prolog) && preg_match('/encoding\\s*=\\s*("([^"]*)"|\'([^\']*)\')/Ui', $prolog[1], $encoding)) {
                        $encoding = substr($encoding[1], 1, -1);
                    } else {
                        if (strpos($data, sprintf('%c%c%c%c', 0x0, 0x0, 0xfe, 0xff)) === 0) {
                            $encoding = 'UTF-32be';
                        } else {
                            if (strpos($data, sprintf('%c%c%c%c', 0xff, 0xfe, 0x0, 0x0)) === 0) {
                                $encoding = 'UTF-32';
                            } else {
                                if (strpos($data, sprintf('%c%c', 0xfe, 0xff)) === 0) {
                                    $encoding = 'UTF-16be';
                                } else {
                                    if (strpos($data, sprintf('%c%c', 0xff, 0xfe)) === 0) {
                                        $encoding = 'UTF-16le';
                                    } else {
                                        if (strpos($data, sprintf('%c%c%c', 0xef, 0xbb, 0xbf)) === 0) {
                                            $encoding = 'UTF-8';
                                        } else {
                                            $encoding = null;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            // Change the encoding to UTF-8 (as we always use UTF-8 internally)
            $data = SimplePie_Misc::change_encoding($data, $encoding, 'UTF-8');
            // Strip illegal characters (if on less  than PHP5, as on PHP5 expat can manage fine)
            if (version_compare(phpversion(), '5', '<')) {
                if (function_exists('iconv')) {
                    $data = iconv('UTF-8', 'UTF-8//IGNORE', $data);
                } else {
                    if (function_exists('mb_convert_encoding')) {
                        $data = mb_convert_encoding($data, 'UTF-8', 'UTF-8');
                    } else {
                        $data = SimplePie_Misc::utf8_bad_replace($data);
                    }
                }
            }
            // Start parsing
            $data = new $this->parser_class($data, 'UTF-8', $this->xml_dump);
            // If we want the XML, just output that and quit
            if ($this->xml_dump) {
                header('Content-type: text/xml; charset=UTF-8');
                echo $data->data;
                exit;
            } else {
                if (!$data->error_code) {
                    // Parse the data, and make it sane
                    $this->sanitize->parse_data_array($data->data, $this->rss_url);
                    unset($data);
                    // Get the sane data
                    $this->data['feedinfo'] = $this->sanitize->feedinfo;
                    unset($this->sanitize->feedinfo);
                    $this->data['info'] = $this->sanitize->info;
                    unset($this->sanitize->info);
                    $this->data['items'] = $this->sanitize->items;
                    unset($this->sanitize->items);
                    $this->data['feedinfo']['encoding'] = $this->sanitize->output_encoding;
                    $this->data['url'] = $this->rss_url;
                    // Store the headers that we need
                    if (!empty($headers['last-modified'])) {
                        $this->data['last-modified'] = $headers['last-modified'];
                    }
                    if (!empty($headers['etag'])) {
                        $this->data['etag'] = $headers['etag'];
                    }
                    // If we want to order it by date, check if all items have a date, and then sort it
                    if ($this->order_by_date && !empty($this->data['items'])) {
                        $do_sort = true;
                        foreach ($this->data['items'] as $item) {
                            if (!$item->get_date('U')) {
                                $do_sort = false;
                                break;
                            }
                        }
                        if ($do_sort) {
                            usort($this->data['items'], create_function('$a, $b', 'if ($a->get_date(\'U\') == $b->get_date(\'U\')) return 1; return ($a->get_date(\'U\') < $b->get_date(\'U\')) ? 1 : -1;'));
                        }
                    }
                    // Cache the file if caching is enabled
                    if ($cache && !$cache->save($this->data)) {
                        $this->error = "{$cache->name} is not writeable";
                        SimplePie_Misc::error($this->error, E_USER_WARNING, __FILE__, __LINE__);
                    }
                    return true;
                } else {
                    $this->error = "XML error: {$data->error_string} at line {$data->current_line}, column {$data->current_column}";
                    SimplePie_Misc::error($this->error, E_USER_WARNING, __FILE__, __LINE__);
                    return false;
                }
            }
        }
    }
开发者ID:jbogota,项目名称:blog-king,代码行数:101,代码来源:class-simplepie-rss.php

示例2: init


//.........这里部分代码省略.........
                        if ($cache) {
                            if (!$cache->save(array('url' => $this->feed_url, 'feed_url' => $file->url, 'build' => SIMPLEPIE_BUILD))) {
                                trigger_error("{$cache->name} is not writeable", E_USER_WARNING);
                            }
                            $cache = new $this->cache_class($this->cache_location, call_user_func($this->cache_name_function, $file->url), 'spc');
                        }
                        $this->feed_url = $file->url;
                    } else {
                        $this->error = "A feed could not be found at {$this->feed_url}";
                        SimplePie_Misc::error($this->error, E_USER_NOTICE, __FILE__, __LINE__);
                        return false;
                    }
                }
                $locate = null;
                $headers = $file->headers;
                $data = trim($file->body);
                unset($file);
            } else {
                $data = $this->raw_data;
            }
            // First check to see if input has been overridden.
            if ($this->input_encoding !== false) {
                $encoding = $this->input_encoding;
            } elseif (isset($headers['content-type']) && preg_match('/;[\\x09\\x20]*charset=([^;]*)/i', $headers['content-type'], $charset)) {
                $encoding = $charset[1];
            } elseif (preg_match("/^<\\?xml[ \t\r\n]+version([ \t\r\n]+)?=([ \t\r\n]+)?(\"1.0\"|'1.0'|\"1.1\"|'1.1')[ \t\r\n]+encoding([ \t\r\n]+)?=([ \t\r\n]+)?(\"[A-Za-z][A-Za-z0-9._\\-]*\"|'[A-Za-z][A-Za-z0-9._\\-]*')([ \t\r\n]+standalone([ \t\r\n]+)?=([ \t\r\n]+)?(\"(yes|no)\"|'(yes|no)'))?([ \t\r\n]+)?\\?>/", $data, $prolog)) {
                $encoding = substr($prolog[6], 1, -1);
            } elseif (strpos($data, "��") === 0) {
                $encoding = 'UTF-32be';
            } elseif (strpos($data, "��") === 0) {
                $encoding = 'UTF-32';
            } elseif (strpos($data, "��") === 0) {
                $encoding = 'UTF-16be';
            } elseif (strpos($data, "��") === 0) {
                $encoding = 'UTF-16le';
            } elseif (strpos($data, "") === 0) {
                $encoding = 'UTF-8';
            } elseif (isset($headers['content-type']) && strtolower(SimplePie_Misc::parse_mime($headers['content-type'])) == 'text/xml') {
                $encoding = 'US-ASCII';
            } elseif (isset($headers['content-type']) && SimplePie_Misc::stripos(SimplePie_Misc::parse_mime($headers['content-type']), 'text/') === 0) {
                $encoding = 'ISO-8859-1';
            } else {
                $encoding = 'UTF-8';
            }
            // Change the encoding to UTF-8 (as we always use UTF-8 internally)
            if ($encoding != 'UTF-8') {
                $data = SimplePie_Misc::change_encoding($data, $encoding, 'UTF-8');
            }
            // Strip illegal characters
            $data = SimplePie_Misc::utf8_bad_replace($data);
            $parser = new $this->parser_class();
            $parser->pre_process($data, 'UTF-8');
            // If we want the XML, just output that and quit
            if ($this->xml_dump) {
                header('Content-type: text/xml; charset=UTF-8');
                echo $data;
                exit;
            } elseif ($parser->parse($data)) {
                unset($data);
                $this->data = $parser->get_data();
                if (isset($this->data['child'])) {
                    if (isset($headers)) {
                        $this->data['headers'] = $headers;
                    }
                    $this->data['build'] = SIMPLEPIE_BUILD;
                    // Cache the file if caching is enabled
                    if ($cache && !$cache->save($this->data)) {
                        trigger_error("{$cache->name} is not writeable", E_USER_WARNING);
                    }
                    return true;
                } else {
                    $this->error = "A feed could not be found at {$this->feed_url}";
                    SimplePie_Misc::error($this->error, E_USER_NOTICE, __FILE__, __LINE__);
                    return false;
                }
            } else {
                $this->error = sprintf('XML error: %s at line %d, column %d', $parser->get_error_string(), $parser->get_current_line(), $parser->get_current_column());
                SimplePie_Misc::error($this->error, E_USER_NOTICE, __FILE__, __LINE__);
                return false;
            }
        } elseif (!empty($this->multifeed_url)) {
            $i = 0;
            $success = 0;
            $this->multifeed_objects = array();
            foreach ($this->multifeed_url as $url) {
                if (SIMPLEPIE_PHP5) {
                    // This keyword needs to defy coding standards for PHP4 compatibility
                    $this->multifeed_objects[$i] = clone $this;
                } else {
                    $this->multifeed_objects[$i] = $this;
                }
                $this->multifeed_objects[$i]->set_feed_url($url);
                $success |= $this->multifeed_objects[$i]->init();
                $i++;
            }
            return (bool) $success;
        } else {
            return false;
        }
    }
开发者ID:pyfun,项目名称:dokuwiki,代码行数:101,代码来源:SimplePie.php


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