本文整理汇总了PHP中xml_get_current_column_number函数的典型用法代码示例。如果您正苦于以下问题:PHP xml_get_current_column_number函数的具体用法?PHP xml_get_current_column_number怎么用?PHP xml_get_current_column_number使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了xml_get_current_column_number函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* PHP5 constructor.
*/
function __construct($source)
{
# Check if PHP xml isn't compiled
#
if (!function_exists('xml_parser_create')) {
return trigger_error("PHP's XML extension is not available. Please contact your hosting provider to enable PHP's XML extension.");
}
$parser = xml_parser_create();
$this->parser = $parser;
# pass in parser, and a reference to this object
# set up handlers
#
xml_set_object($this->parser, $this);
xml_set_element_handler($this->parser, 'feed_start_element', 'feed_end_element');
xml_set_character_data_handler($this->parser, 'feed_cdata');
$status = xml_parse($this->parser, $source);
if (!$status) {
$errorcode = xml_get_error_code($this->parser);
if ($errorcode != XML_ERROR_NONE) {
$xml_error = xml_error_string($errorcode);
$error_line = xml_get_current_line_number($this->parser);
$error_col = xml_get_current_column_number($this->parser);
$errormsg = "{$xml_error} at line {$error_line}, column {$error_col}";
$this->error($errormsg);
}
}
xml_parser_free($this->parser);
$this->normalize();
}
示例2: parseError
function parseError( $parser )
{
$error = xml_error_string( xml_get_error_code( $parser ) );
$errorLine = xml_get_current_line_number( $parser );
$errorColumn = xml_get_current_column_number( $parser );
return "<b>Error: $error at line $errorLine column $errorColumn</b>";
}
示例3: formatMetadata
/**
* Format resource metadata.
*
* @param resource $value
*
* @return string
*/
protected function formatMetadata($value)
{
$props = array();
switch (get_resource_type($value)) {
case 'stream':
$props = stream_get_meta_data($value);
break;
case 'curl':
$props = curl_getinfo($value);
break;
case 'xml':
$props = array('current_byte_index' => xml_get_current_byte_index($value), 'current_column_number' => xml_get_current_column_number($value), 'current_line_number' => xml_get_current_line_number($value), 'error_code' => xml_get_error_code($value));
break;
}
if (empty($props)) {
return '{}';
}
$formatted = array();
foreach ($props as $name => $value) {
$formatted[] = sprintf('%s: %s', $name, $this->indentValue($this->presentSubValue($value)));
}
$template = sprintf('{%s%s%%s%s}', PHP_EOL, self::INDENT, PHP_EOL);
$glue = sprintf(',%s%s', PHP_EOL, self::INDENT);
return sprintf($template, implode($glue, $formatted));
}
示例4: error
function error($msg)
{
$errf = $this->error_func;
$line = xml_get_current_line_number($this->parser);
$col = xml_get_current_column_number($this->parser);
$errf("{$msg} at line:{$line}, col:{$col}.");
}
示例5: get_posts
function get_posts()
{
if (!$this->fp) {
echo "File pointer failed to init.";
return false;
}
$this->parser = xml_parser_create("UTF-8");
xml_set_object($this->parser, $this);
xml_set_element_handler($this->parser, 'startXML', 'endXML');
xml_set_character_data_handler($this->parser, 'charXML');
xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, false);
xml_parser_set_option($this->parser, XML_OPTION_TARGET_ENCODING, 'UTF-8');
$state = 0;
while (!feof($this->fp)) {
$chunk = fread($this->fp, 8192);
// read in 8KB chunks (8192 bytes)
if ($state == 0 && trim($chunk) == '') {
continue;
// scan until it reacheas something (just in case)
} elseif ($state == 0 && strpos($chunk, '<?xml') !== false) {
// the first chunk, probably includes the header(s)
$chunk = preg_replace('#<\\?xml.+?>#i', '', $chunk);
// remove the header(s) from the first chunk
$state = 1;
}
if (!xml_parse($this->parser, $chunk, feof($this->fp))) {
$this->error(sprintf('XML error at line %d column %d', xml_get_current_line_number($this->parser), xml_get_current_column_number($this->parser)) . ' -' . xml_error_string(xml_get_error_code($this->parser)));
}
}
return $this->posts;
}
示例6: __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);
}
示例7: xmlize
/**
* Create an array structure from an XML string.
*
* Usage:<br>
* <code>
* $xml = xmlize($array);
* </code>
* See the function {@link traverse_xmlize()} for information about the
* structure of the array, it's much easier to explain by showing you.
* Be aware that the array is somewhat tricky. I use xmlize all the time,
* but still need to use {@link traverse_xmlize()} quite often to show me the structure!
*
* THIS IS A PHP 5 VERSION:
*
* This modified version basically has a new optional parameter
* to specify an OUTPUT encoding. If not specified, it defaults to UTF-8.
* I recommend you to read this PHP bug. There you can see how PHP4, PHP5.0.0
* and PHP5.0.2 will handle this.
* {@link http://bugs.php.net/bug.php?id=29711}
* Ciao, Eloy :-)
*
* @param string $data The XML source to parse.
* @param int $whitespace If set to 1 allows the parser to skip "space" characters in xml document. Default is 1
* @param string $encoding Specify an OUTPUT encoding. If not specified, it defaults to UTF-8.
* @param bool $reporterrors if set to true, then a {@link xml_format_exception}
* exception will be thrown if the XML is not well-formed. Otherwise errors are ignored.
* @return array representation of the parsed XML.
*/
function xmlize($data, $whitespace = 1, $encoding = 'UTF-8', $reporterrors = false)
{
$data = trim($data);
$vals = array();
$parser = xml_parser_create($encoding);
xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, $whitespace);
xml_parse_into_struct($parser, $data, $vals);
// Error handling when the xml file is not well-formed
if ($reporterrors) {
$errorcode = xml_get_error_code($parser);
if ($errorcode) {
$exception = new xml_format_exception(xml_error_string($errorcode), xml_get_current_line_number($parser), xml_get_current_column_number($parser));
xml_parser_free($parser);
throw $exception;
}
}
xml_parser_free($parser);
$i = 0;
if (empty($vals)) {
// XML file is invalid or empty, return false
return false;
}
$array = array();
$tagname = $vals[$i]['tag'];
if (isset($vals[$i]['attributes'])) {
$array[$tagname]['@'] = $vals[$i]['attributes'];
} else {
$array[$tagname]['@'] = array();
}
$array[$tagname]["#"] = xml_depth($vals, $i);
return $array;
}
示例8: MagpieRSS
function MagpieRSS($source)
{
# if PHP xml isn't compiled in, die
#
if (!function_exists('xml_parser_create')) {
trigger_error("Failed to load PHP's XML Extension. http://www.php.net/manual/en/ref.xml.php");
}
$parser = @xml_parser_create();
if (!is_resource($parser)) {
trigger_error("Failed to create an instance of PHP's XML parser. http://www.php.net/manual/en/ref.xml.php");
}
$this->parser = $parser;
# pass in parser, and a reference to this object
# set up handlers
#
xml_set_object($this->parser, $this);
xml_set_element_handler($this->parser, 'feed_start_element', 'feed_end_element');
xml_set_character_data_handler($this->parser, 'feed_cdata');
$status = xml_parse($this->parser, $source);
if (!$status) {
$errorcode = xml_get_error_code($this->parser);
if ($errorcode != XML_ERROR_NONE) {
$xml_error = xml_error_string($errorcode);
$error_line = xml_get_current_line_number($this->parser);
$error_col = xml_get_current_column_number($this->parser);
$errormsg = "{$xml_error} at line {$error_line}, column {$error_col}";
$this->error($errormsg);
}
}
xml_parser_free($this->parser);
$this->normalize();
}
示例9: ParserError
function ParserError($XMLParser)
{
unset($this->arrFeedItems);
unset($this->arrItemData);
$this->arrFeedItems['error_code'] = xml_get_error_code($XMLParser);
$this->arrFeedItems['line_number'] = xml_get_current_line_number($XMLParser);
$this->arrFeedItems['column_number'] = xml_get_current_column_number($XMLParser);
}
示例10: get_xml_error
/** Get the xml error if an an error in the xml file occured during parsing. */
public function get_xml_error()
{
if ($this->parse_error) {
$errCode = xml_get_error_code($this->parser);
$thisError = "Error Code [" . $errCode . "] \"<strong style='color:red;'>" . xml_error_string($errCode) . "</strong>\",\n at char " . xml_get_current_column_number($this->parser) . "\n on line " . xml_get_current_line_number($this->parser) . "";
} else {
$thisError = $this->parse_error;
}
return $thisError;
}
示例11: _parse
protected function _parse($data = '')
{
// Deprecation warning.
MLog::add('MSimpleXML::_parse() is deprecated.', MLog::WARNING, 'deprecated');
//Error handling
if (!xml_parse($this->_parser, $data)) {
$this->_handleError(xml_get_error_code($this->_parser), xml_get_current_line_number($this->_parser), xml_get_current_column_number($this->_parser));
}
//Free the parser
xml_parser_free($this->_parser);
}
示例12: castXml
public static function castXml($h, array $a, Stub $stub, $isNested)
{
$a['current_byte_index'] = xml_get_current_byte_index($h);
$a['current_column_number'] = xml_get_current_column_number($h);
$a['current_line_number'] = xml_get_current_line_number($h);
$a['error_code'] = xml_get_error_code($h);
if (isset(self::$xmlErrors[$a['error_code']])) {
$a['error_code'] = new ConstStub(self::$xmlErrors[$a['error_code']], $a['error_code']);
}
return $a;
}
示例13: create
/**
* Factory XML parsing exception.
*
* @param resource $parser
* @throws static
*/
public static function create($parser)
{
if (!is_resource($parser) || 'xml' !== get_resource_type($parser)) {
$message = 'Argument #1 of "' . __CLASS__ . '::' . __METHOD__ . '" must be a resource returned by "xml_parser_create"';
throw new InvalidArgumentException($message);
}
$code = xml_get_error_code($parser);
$error = xml_error_string($code);
$line = xml_get_current_line_number($parser);
$column = xml_get_current_column_number($parser);
return new static(sprintf('XML parsing error: "%s" at Line %d at column %d', $error, $line, $column), $code);
}
示例14: __construct
public function __construct($message, $parser, \SplFileObject $file = NULL)
{
$this->code = xml_get_error_code($parser);
if (false === $this->code) {
throw new \BadMethodCallException('This is not a valid xml_parser resource.');
}
parent::__construct($message ?: xml_error_string($this->code), $this->code);
$this->file = $file ? $file->getPathname() : '(data stream)';
$this->line = xml_get_current_line_number($parser);
$this->err['srcColumn'] = xml_get_current_column_number($parser);
$this->err['srcIndex'] = xml_get_current_byte_index($parser);
}
示例15: Parse
function Parse($data)
{
if (!xml_parse($this->parser, $data)) {
$this->data = array();
$this->errorCode = xml_get_error_code($this->parser);
$this->errorString = xml_error_string($this->errorCode);
$this->currentLine = xml_get_current_line_number($this->parser);
$this->currentColumn = xml_get_current_column_number($this->parser);
} else {
$this->data = $this->data['child'];
}
xml_parser_free($this->parser);
}