本文整理汇总了PHP中xml_parser_set_option函数的典型用法代码示例。如果您正苦于以下问题:PHP xml_parser_set_option函数的具体用法?PHP xml_parser_set_option怎么用?PHP xml_parser_set_option使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了xml_parser_set_option函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: parse
public function parse($xml_or_arr)
{
if (is_array($xml_or_arr)) {
$output = array();
foreach ($xml_or_arr as $val) {
$to = $this->parse($val);
$output = array_merge($output, $to);
}
return $output;
}
// echo '<h1>xml in parser:</h1><pre>'; print_r($xml); echo '</pre>';
// if we don't start with a processing instruction,
// we add an outer node just to ensure it's a valid xml document
// (i.e. only a single root node)
if (substr($xml_or_arr, 0, 2) != '<?') {
$xml_or_arr = "<{$this->insertedNode}>" . $xml_or_arr . "</{$this->insertedNode}>";
}
$this->parser = xml_parser_create();
xml_set_object($this->parser, $this);
xml_set_element_handler($this->parser, "tagOpen", "tagClosed");
xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, 0);
xml_parser_set_option($this->parser, XML_OPTION_SKIP_WHITE, 1);
xml_set_character_data_handler($this->parser, "tagData");
$this->xmldata = xml_parse($this->parser, $xml_or_arr);
if (!$this->xmldata) {
die(sprintf("XML error: %s at line %d", xml_error_string(xml_get_error_code($this->parser)), xml_get_current_line_number($this->parser)));
}
xml_parser_free($this->parser);
$this->parseCompleted();
return $this->output;
}
开发者ID:ilri,项目名称:genebank-gg_server,代码行数:31,代码来源:parsers.php
示例2: _parse_proppatch
/**
* constructor
*
* @param string path of input stream
* @access public
*/
function _parse_proppatch($path)
{
$this->success = true;
$this->depth = 0;
$this->props = array();
$had_input = false;
$f_in = fopen($path, "r");
if (!$f_in) {
$this->success = false;
return;
}
$xml_parser = xml_parser_create_ns("UTF-8", " ");
xml_set_element_handler($xml_parser, array(&$this, "_startElement"), array(&$this, "_endElement"));
xml_set_character_data_handler($xml_parser, array(&$this, "_data"));
xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, false);
while ($this->success && !feof($f_in)) {
$line = fgets($f_in);
if (is_string($line)) {
$had_input = true;
$this->success &= xml_parse($xml_parser, $line, false);
}
}
if ($had_input) {
$this->success &= xml_parse($xml_parser, "", true);
}
xml_parser_free($xml_parser);
fclose($f_in);
}
开发者ID:klr2003,项目名称:sourceread,代码行数:34,代码来源:_parse_proppatch.php
示例3: go
/**
* Run the loader, to load up field-restrictions from the XML file.
*
* @param string The default breadcrumbs
* @param string The breadcrumb XML data
*/
function go($current_breadcrumbs, $data)
{
$this->tag_stack = array();
$this->attribute_stack = array();
$this->substitution_current_match_key = NULL;
$this->substitution_current_label = NULL;
$this->links = array();
$this->substitutions = array();
$breadcrumb_tpl = do_template('BREADCRUMB_ESCAPED');
$this->breadcrumb_tpl = $breadcrumb_tpl->evaluate();
$this->current_breadcrumbs = $current_breadcrumbs;
// Create and setup our parser
$xml_parser = @xml_parser_create();
if ($xml_parser === false) {
return;
// PHP5 default build on windows comes with this function disabled, so we need to be able to escape on error
}
xml_set_object($xml_parser, $this);
@xml_parser_set_option($xml_parser, XML_OPTION_TARGET_ENCODING, get_charset());
@xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, 0);
xml_set_element_handler($xml_parser, 'startElement', 'endElement');
xml_set_character_data_handler($xml_parser, 'startText');
// Run the parser
if (@xml_parse($xml_parser, $data, true) == 0) {
attach_message('breadcrumbs.xml: ' . xml_error_string(xml_get_error_code($xml_parser)), 'warn');
return;
}
@xml_parser_free($xml_parser);
}
开发者ID:erico-deh,项目名称:ocPortal,代码行数:35,代码来源:breadcrumbs.php
示例4: load
function load($xml_file)
{
$this->_path = dirname($xml_file);
if (!file_exists($xml_file)) {
return;
}
$fp = @fopen($xml_file, "r");
if ($fp) {
$data = '';
while (!feof($fp)) {
$data .= fread($fp, 8192);
}
fclose($fp);
if (ini_get("magic_quotes_gpc")) {
$data = stripslashes($data);
}
}
$this->_parser = xml_parser_create('UTF-8');
xml_set_object($this->_parser, $this);
xml_set_element_handler($this->_parser, "_saxStartElement", "_saxEndElement");
xml_parser_set_option($this->_parser, XML_OPTION_TARGET_ENCODING, "UTF-8");
if (!xml_parse($this->_parser, $data, true)) {
trigger_error(sprintf("Language pack loading failed, XML error: %s at line %d.", xml_error_string(xml_get_error_code($this->_parser)), xml_get_current_line_number($this->_parser)), E_USER_ERROR);
}
xml_parser_free($this->_parser);
}
开发者ID:Vladimir25,项目名称:marykay,代码行数:26,代码来源:ClientResources.php
示例5: __construct
public function __construct($input, $maxDepth = 20)
{
if (!is_string($input)) {
throw new XmlToArrayException('No valid input.');
}
$this->_maxDepth = $maxDepth;
$XMLParser = xml_parser_create();
xml_parser_set_option($XMLParser, XML_OPTION_SKIP_WHITE, false);
xml_parser_set_option($XMLParser, XML_OPTION_CASE_FOLDING, false);
xml_parser_set_option($XMLParser, XML_OPTION_TARGET_ENCODING, 'UTF-8');
xml_set_character_data_handler($XMLParser, array($this, '_contents'));
xml_set_default_handler($XMLParser, array($this, '_default'));
xml_set_element_handler($XMLParser, array($this, '_start'), array($this, '_end'));
xml_set_external_entity_ref_handler($XMLParser, array($this, '_externalEntity'));
xml_set_notation_decl_handler($XMLParser, array($this, '_notationDecl'));
xml_set_processing_instruction_handler($XMLParser, array($this, '_processingInstruction'));
xml_set_unparsed_entity_decl_handler($XMLParser, array($this, '_unparsedEntityDecl'));
if (!xml_parse($XMLParser, $input, true)) {
$errorCode = xml_get_error_code($XMLParser);
$message = sprintf('%s. line: %d, char: %d' . ($this->_tagStack ? ', tag: %s' : ''), xml_error_string($errorCode), xml_get_current_line_number($XMLParser), xml_get_current_column_number($XMLParser) + 1, implode('->', $this->_tagStack));
xml_parser_free($XMLParser);
throw new XmlToArrayException($message, $errorCode);
}
xml_parser_free($XMLParser);
}
开发者ID:rodhoff,项目名称:MNW,代码行数:25,代码来源:xml_to_array.php
示例6: parse
function parse($xml)
{
$this->result = array();
$this->context = $xml;
$this->currentTag = '';
$this->currentState = array();
$this->xmlParser = xml_parser_create();
xml_parser_set_option($this->xmlParser, XML_OPTION_TARGET_ENCODING, "UTF-8") . xml_set_object($this->xmlParser, $this);
xml_set_element_handler($this->xmlParser, 'startElement', 'endElement');
xml_set_character_data_handler($this->xmlParser, 'content');
$this->trigger('before:import');
try {
if (!xml_parse($this->xmlParser, $xml)) {
$this->xmlParserError = 'Line ' . xml_get_current_line_number($this->xmlParser) . ': ' . (xml_get_error_code($this->xmlParser) ? xml_error_string(xml_get_error_code($this->xmlParser)) : 'Unknown error');
}
} catch (Exception $e) {
$this->xmlParserError = $e->getMessage();
}
xml_parser_free($this->xmlParser);
if ($this->xmlParserError) {
$this->raiseError($this->xmlParserError);
} else {
if ($this->getCurrentState()) {
$this->raiseError('Wrong ending state: ' . $this->getCurrentState());
} else {
}
}
$this->trigger('after:import');
return $this->result;
}
开发者ID:jagermesh,项目名称:bright,代码行数:30,代码来源:BrXMLParser.php
示例7: fetch
public function fetch()
{
$this->query = $this->url . '?pid=' . $this->pid . '&noredirect=true&format=unixref&id=doi%3A' . $this->doi;
$request_options = array('method' => 'POST');
$result = drupal_http_request($this->query, $request_options);
if ($result->code != 200) {
drupal_set_message(t('HTTP error: !error when trying to contact crossref.org for XML input', array('!error' => $result->code)), 'error');
return;
}
if (empty($result->data)) {
drupal_set_message(t('Did not get any data from crossref.org'), 'error');
return;
}
$sxml = @simplexml_load_string($result->data);
if ($error = (string) $sxml->doi_record->crossref->error) {
drupal_set_message($error, 'error');
return;
}
$this->nodes = array();
$this->parser = drupal_xml_parser_create($result->data);
// use case-folding so we are sure to find the tag in
xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, FALSE);
xml_parser_set_option($this->parser, XML_OPTION_SKIP_WHITE, TRUE);
xml_set_object($this->parser, $this);
xml_set_element_handler($this->parser, 'unixref_startElement', 'unixref_endElement');
xml_set_character_data_handler($this->parser, 'unixref_characterData');
if (!xml_parse($this->parser, $result->data)) {
drupal_set_message(sprintf("XML error: %s at line %d", xml_error_string(xml_get_error_code($this->parser)), xml_get_current_line_number($this->parser)), 'error');
}
xml_parser_free($this->parser);
return $this->node;
}
开发者ID:khoegenauer,项目名称:exframe,代码行数:32,代码来源:biblio.crossref.client.php
示例8: xml
public function xml() {
$this->parser = xml_parser_create();
xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, false);
xml_set_object($this->parser, $this);
xml_set_element_handler($this->parser, 'open','close');
xml_set_character_data_handler($this->parser, 'data');
}
开发者ID:panhongsheng,项目名称:zl_cms,代码行数:7,代码来源:xml.class.php
示例9: get_xml_tree
/**
* 获取xml树
* @param string $xmldata xml数据
* @param array $result xml内容
*/
static function get_xml_tree($xmldata, &$result)
{
ini_set('track_errors', '1');
$xmlreaderror = false;
$parser = xml_parser_create();
xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
if (!xml_parse_into_struct($parser, $xmldata, $vals, $index)) {
$xmlreaderror = true;
return 0;
}
xml_parser_free($parser);
if (!$xmlreaderror) {
$result = array();
$i = 0;
if (isset($vals[$i]['attributes'])) {
foreach (array_keys($vals[$i]['attributes']) as $attkey) {
$attributes[$attkey] = $vals[$i]['attributes'][$attkey];
}
}
$result[$vals[$i]['tag']] = array_merge((array) $attributes, self::get_children($vals, $i, 'open'));
}
ini_set('track_errors', '0');
return 1;
}
开发者ID:jianchengdu,项目名称:dangjia,代码行数:30,代码来源:XmlTool.php
示例10: AbstractSAXParser
function AbstractSAXParser()
{
// create a parser
$this->parserResource = xml_parser_create();
if (isset($this->parserResource)) {
// allowing object instance to use the xml parser
xml_set_object($this->parserResource, $this);
// set tag event handler
xml_set_element_handler($this->parserResource, "startTagElement", "endTagElement");
// set CDATA event handler
xml_set_character_data_handler($this->parserResource, "cdataElement");
// set processing instruction handler
xml_set_processing_instruction_handler($this->parserResource, "instructionElement");
// set undeclare entity
xml_set_unparsed_entity_decl_handler($this->parserResource, "undeclaredEntityElement");
// set notation delcaration handler
xml_set_notation_decl_handler($this->parserResource, "notationDeclarationElement");
// set external entity handler
xml_set_external_entity_ref_handler($this->parserResource, "externalEntityElement");
// seat default parser option
xml_parser_set_option($this->parserResource, XML_OPTION_SKIP_WHITE, 1);
xml_parser_set_option($this->parserResource, XML_OPTION_CASE_FOLDING, 0);
xml_parser_set_option($this->parserResource, XML_OPTION_TARGET_ENCODING, 'UTF-8');
}
}
开发者ID:alexpagnoni,项目名称:jphp,代码行数:25,代码来源:AbstractSAXParser.php
示例11: processXML
function processXML($filename)
{
// read the xml document
$data = implode("", file($filename));
$parser = xml_parser_create();
xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
xml_parse_into_struct($parser, $data, $values, $tags);
xml_parser_free($parser);
$talks = array();
// loop through the structures
foreach ($tags as $key => $val) {
if ($key == "talk") {
$ranges = $val;
$nranges = count($ranges);
// each contiguous pair of array entries are the
// lower and upper range for each talk elements
for ($i = 0; $i < $nranges; $i += 2) {
$offset = $ranges[$i] + 1;
$len = $ranges[$i + 1] - $offset;
$talks[] =& parseTalk(array_slice($values, $offset, $len));
}
} else {
continue;
}
}
return $talks;
}
开发者ID:SandyS1,项目名称:presentations,代码行数:28,代码来源:rss_create.php
示例12: replaceTranslation
public function replaceTranslation()
{
//write xml header
fwrite($this->outputFP, '<?xml version="1.0" encoding="UTF-8"?>');
//create parser
$xml_parser = xml_parser_create('UTF-8');
//configure parser
//pass this object to parser to make its variables and functions visible inside callbacks
xml_set_object($xml_parser, $this);
//avoid uppercasing all tags name
xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, false);
//define callbacks for tags
xml_set_element_handler($xml_parser, "tagOpen", "tagClose");
//define callback for data
xml_set_character_data_handler($xml_parser, "characterData");
//read a chunk of text
while ($this->currentBuffer = fread($this->originalFP, 4096)) {
/*
preprocess file
*/
// obfuscate entities because sax automatically does html_entity_decode
$temporary_check_buffer = preg_replace("/&(.*?);/", '#%$1#%', $this->currentBuffer);
$lastByte = $temporary_check_buffer[strlen($temporary_check_buffer) - 1];
//avoid cutting entities in half:
//the last fread could have truncated an entity (say, '<' in '&l'), thus invalidating the escaping
//***** and if there is an & that it is not an entity, this is an infinite loop !!!!!
$escape_AMP = false;
// 9 is the max length of an entity. So, suppose that the & is at the end of buffer,
// add 9 Bytes and substitute the entities, if the & is present and it is not at the end
//it can't be a entity, exit the loop
while (true) {
$_ampPos = strpos($temporary_check_buffer, '&');
//check for real entity or escape it to safely exit from the loop!!!
if ($_ampPos === false || strlen(substr($temporary_check_buffer, $_ampPos)) > 9) {
$escape_AMP = true;
break;
}
//if an entity is still present, fetch some more and repeat the escaping
$this->currentBuffer .= fread($this->originalFP, 9);
$temporary_check_buffer = preg_replace("/&(.*?);/", '#%$1#%', $this->currentBuffer);
}
//free stuff outside the loop
unset($temporary_check_buffer);
$this->currentBuffer = preg_replace("/&(.*?);/", '#%$1#%', $this->currentBuffer);
if ($escape_AMP) {
$this->currentBuffer = str_replace("&", '#%amp#%', $this->currentBuffer);
}
//get lenght of chunk
$this->len = strlen($this->currentBuffer);
//parse chunk of text
if (!xml_parse($xml_parser, $this->currentBuffer, feof($this->originalFP))) {
//if unable, die
die(sprintf("XML error: %s at line %d", xml_error_string(xml_get_error_code($xml_parser)), xml_get_current_line_number($xml_parser)));
}
//get accumulated this->offset in document: as long as SAX pointer advances, we keep track of total bytes it has seen so far; this way, we can translate its global pointer in an address local to the current buffer of text to retrieve last char of tag
$this->offset += $this->len;
}
//close parser
xml_parser_free($xml_parser);
}
开发者ID:indynagpal,项目名称:MateCat,代码行数:60,代码来源:XliffSAXTranslationReplacer.php
示例13: getPushList
/**
* rss push
*/
public function getPushList($id)
{
$rssInfo = $this->where('id=' . $id)->find();
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $rssInfo['url']);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch);
curl_close($ch);
$parser = xml_parser_create();
xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
xml_parse_into_struct($parser, $result, $values, $tags);
xml_parser_free($parser);
for ($i = 0; $i < $rssInfo['count']; $i++) {
foreach ($tags as $k => $v) {
if ($k == 'title') {
$newsList[$i]['title'] = $values[$v[$i + 2]]['value'];
} elseif ($k == 'description') {
$description = $values[$v[$i + 1]]['value'];
//如果简介中有图片,就将其作为图文封面
$pattern = '/<img(.*)src="(.*)"/Us';
preg_match($pattern, $description, $content);
$newsList[$i]['cover'] = $content['2'];
$newsList[$i]['description'] = $values[$v[$i + 1]]['value'];
} elseif ($k == 'link') {
$newsList[$i]['url'] = $values[$v[$i + 2]]['value'];
}
}
}
return $newsList;
}
开发者ID:alic1234567890,项目名称:wshowco,代码行数:34,代码来源:WechatRssModel.class.php
示例14: run
/**
* @param $fname
*/
private function run($fname)
{
$parser = xml_parser_create_ns('UTF-8');
// case folding violates XML standard, turn it off
xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, false);
xml_set_element_handler($parser, array($this, 'rootElementOpen'), false);
if (file_exists($fname)) {
$file = fopen($fname, "rb");
if ($file) {
do {
$chunk = fread($file, 32768);
$ret = xml_parse($parser, $chunk, feof($file));
if ($ret == 0) {
// XML isn't well-formed!
fclose($file);
xml_parser_free($parser);
return;
}
} while (!feof($file));
fclose($file);
}
}
$this->wellFormed = true;
xml_parser_free($parser);
}
开发者ID:Grprashanthkumar,项目名称:ColfusionWeb,代码行数:28,代码来源:XmlTypeCheck.php
示例15: XMLToArray
function XMLToArray($data, $ignore = array(), $replace = array(), $showattribs = false, $toupper = false)
{
$this->_showAttribs = $showattribs;
$this->_parser = xml_parser_create();
xml_set_object($this->_parser, $this);
if ($toupper) {
foreach ((array) $ignore as $key => $value) {
$this->_ignore[strtoupper($key)] = strtoupper($value);
}
foreach ((array) $replace as $key => $value) {
$this->_replace[strtoupper($key)] = strtoupper($value);
}
xml_parser_set_option($this->_parser, XML_OPTION_CASE_FOLDING, true);
} else {
$this->_ignore =& $ignore;
$this->_replace =& $replace;
xml_parser_set_option($this->_parser, XML_OPTION_CASE_FOLDING, false);
}
xml_set_element_handler($this->_parser, '_startElement', '_endElement');
xml_set_character_data_handler($this->_parser, '_cdata');
$this->_data = array();
$this->_level = 0;
if (!xml_parse($this->_parser, $data, true)) {
//new Error("XML Parse Error: ".xml_error_string(xml_get_error_code($this->_parser))."n on line: ".xml_get_current_line_number($this->_parser),true);
return false;
}
xml_parser_free($this->_parser);
}
开发者ID:reuf,项目名称:laravel-vzaar,代码行数:28,代码来源:XMLToArray.php
示例16: parseXML
public function parseXML($xml)
{
$xmlArray = null;
$parser = xml_parser_create();
xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, false);
xml_parse_into_struct($parser, $xml, $xmlArray, $indexdata);
xml_parser_free($parser);
$elements = array();
$child = array();
foreach ($xmlArray as $item) {
$current = count($elements);
if ($item['type'] == 'open' || $item['type'] == 'complete') {
$elements[$current] = new \stdClass();
$elements[$current]->tag = $item['tag'];
$elements[$current]->attributes = array_key_exists('attributes', $item) ? $item['attributes'] : '';
$elements[$current]->value = array_key_exists('value', $item) ? $item['value'] : '';
if ($item['type'] == "open") {
$elements[$current]->children = array();
$child[count($child)] =& $elements;
$elements =& $elements[$current]->children;
}
} else {
if ($item['type'] == 'close') {
$elements =& $child[count($child) - 1];
unset($child[count($child) - 1]);
}
}
}
if ($elements) {
return $elements[0];
} else {
return null;
}
}
开发者ID:EP-NY,项目名称:FeedMe,代码行数:35,代码来源:FeedMe_FeedXMLService.php
示例17: create
/**
* @return resource
*/
protected function create()
{
$parser = xml_parser_create("UTF-8");
xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
return $parser;
}
开发者ID:bcncommerce,项目名称:serializer,代码行数:10,代码来源:XmlParser.php
示例18: fetch
function fetch($raw_xml, $final = true)
{
$this->log .= 'fetch() called.' . PHP_EOL;
$this->log .= 'Raw XML:' . PHP_EOL . $raw_xml . PHP_EOL . PHP_EOL;
$this->index = 0;
$this->data = new stdClass();
$this->stack = array();
$this->stack[] =& $this->data;
$this->parser = xml_parser_create('UTF-8');
xml_set_object($this->parser, $this);
xml_set_element_handler($this->parser, 'tag_open', 'tag_close');
xml_set_character_data_handler($this->parser, 'cdata');
xml_parser_set_option($this->parser, XML_OPTION_TARGET_ENCODING, 'UTF-8');
xml_parser_set_option($this->parser, XML_OPTION_SKIP_WHITE, 1);
xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, false);
$start = 0;
$length = strlen($raw_xml);
$chunk_size = 32 * 1024 * 1024;
$ret = true;
while (true) {
if (!($parsed_xml = xml_parse($this->parser, substr($raw_xml, $start, $chunk_size), $final = ($start += $chunk_size) >= $length ? true : false))) {
$this->log .= $ret = sprintf('XML error: %s at line %d.', xml_error_string(xml_get_error_code($this->parser)), xml_get_current_line_number($this->parser));
break;
} else {
if ($final) {
break;
}
}
}
xml_parser_free($this->parser);
return $ret;
}
开发者ID:nickhype,项目名称:HackeyWalk-site-backup,代码行数:32,代码来源:xml.php
示例19: _loadTranslationData
/**
* Load translation data (TMX file reader)
*
* @param string $filename TMX file to add, full path must be given for access
* @param string $locale Locale has no effect for TMX because TMX defines all languages within
* the source file
* @param array $option OPTIONAL Options to use
* @throws Zend_Translation_Exception
*/
protected function _loadTranslationData($filename, $locale, array $options = array())
{
$options = array_merge($this->_options, $options);
if ($options['clear']) {
$this->_translate = array();
}
if (in_array('defined_language', $options) and !empty($options['defined_language'])) {
$this->_defined = true;
}
if (!is_readable($filename)) {
require_once 'Zend/Translate/Exception.php';
throw new Zend_Translate_Exception('Translation file \'' . $filename . '\' is not readable.');
}
$this->_file = xml_parser_create();
xml_set_object($this->_file, $this);
xml_parser_set_option($this->_file, XML_OPTION_CASE_FOLDING, 0);
xml_set_element_handler($this->_file, "_startElement", "_endElement");
xml_set_character_data_handler($this->_file, "_contentElement");
if (!xml_parse($this->_file, file_get_contents($filename))) {
$ex = sprintf('XML error: %s at line %d', xml_error_string(xml_get_error_code($this->_file)), xml_get_current_line_number($this->_file));
xml_parser_free($this->_file);
require_once 'Zend/Translate/Exception.php';
throw new Zend_Translate_Exception($ex);
}
}
开发者ID:dalinhuang,项目名称:popo,代码行数:34,代码来源:Tmx.php
示例20: discuz
/**
* 使用discuz词库
* @param unknown_type $title
* @param unknown_type $content
*/
public static function discuz($title = '', $content = '')
{
$subjectenc = rawurlencode(strip_tags($title));
$messageenc = rawurlencode(strip_tags(preg_replace("/\\[.+?\\]/U", '', $content)));
$data = @implode('', file("http://keyword.discuz.com/related_kw.html?title={$subjectenc}&content={$messageenc}&ics=utf-8&ocs=utf-8"));
if ($data) {
$parser = xml_parser_create();
xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
xml_parse_into_struct($parser, $data, $values, $index);
xml_parser_free($parser);
$kws = array();
foreach ($values as $valuearray) {
if ($valuearray['tag'] == 'kw' || $valuearray['tag'] == 'ekw') {
$kws[] = trim($valuearray['value']);
}
}
$return = '';
if ($kws) {
foreach ($kws as $kw) {
$kw = CHtml::encode(strip_tags($kw));
$return .= $dot . $kw;
$dot = ',';
}
$return = trim($return);
}
return $return;
}
}
开发者ID:zywh,项目名称:maplecity,代码行数:34,代码来源:XAutoKeyword.php
注:本文中的xml_parser_set_option函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论