本文整理汇总了PHP中Parser::load方法的典型用法代码示例。如果您正苦于以下问题:PHP Parser::load方法的具体用法?PHP Parser::load怎么用?PHP Parser::load使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Parser
的用法示例。
在下文中一共展示了Parser::load方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: load
public static function load($input)
{
$file = '';
if (strpos($input, "\n") === false && is_file($input)) {
if (false === is_readable($input)) {
throw new ParseException(sprintf('Unable to parse "%s" as the file is not readable.', $input));
}
$file = $input;
$input = file_get_contents($file);
}
$parser = new Parser();
return $parser->load($input);
}
示例2: testDumpLoad
function testDumpLoad()
{
$tokens = ['d' => '[0-9]+', 'a', 'b', 'c', 'sp' => '\\s+'];
$rules = ['A' => [[['d', ['+', ['|', 'a', 'b']], 'B'], true]], 'B' => [[['d'], true]]];
$lexer = new Lexer($tokens);
$parser = new Parser();
$parser->setLexer($lexer);
$parser->init($rules);
$parser->setSkipTokens(['sp']);
$data = $parser->dump();
$s = serialize($data);
$e = var_export($data, true);
$parser = new Parser();
$parser->setLexer($lexer);
$v = eval("return {$e};");
$parser->load($v);
$parser->tree('123 a a b 1244');
$parser = new Parser();
$parser->setLexer($lexer);
$data = unserialize($s);
$parser->load($data);
$parser->tree('123 a a b 1244');
ob_start();
$parser->printTree('123 a a b 1244');
$text = ob_get_clean();
$this->assertTrue(is_string($text));
}
示例3: toUnixTimestamp
include OLIB_PATH . '/class.parser.php';
include OLIB_PATH . '/class.printjob.php';
include OLIB_PATH . '/class.cfg.php';
error_reporting(E_ERROR);
// setlocale(LC_ALL, 'ru_RU');
function toUnixTimestamp($d, $t)
{
return mktime(substr($t, 0, 2), substr($t, 3, 2), 0, substr($d, 3, 2), substr($d, 0, 2), substr($d, 6, 4));
}
$fn = '/home/webserver/PCOUNTER.LOG';
//$fn = '/home/webserver/PCOUNTER_2010_06.LOG';
$cn = 'printjoblogposition';
$tst = new Parser(array('username', 'document', 'prnname', 'date', 'time', 'pc', 'f1', 'f2', 'paper', 'param', 'size', 'pages', 'n1', 'n2'), ',');
$tst->fileOpen($fn, $cn);
while ($str = $tst->fileStr()) {
$tst->load($str);
$ora = new PrintJob();
$ora->username[0] = substr($tst->username, 4);
$ora->docum[0] = convert_cyr_string(addslashes(str_replace('\'', '', $tst->document)), 'd', 'w');
$ora->prnname[0] = substr($tst->prnname, strpos($tst->prnname, '\\', 3) + 1);
$ora->pcname[0] = substr($tst->pc, 2);
$ora->paper[0] = $tst->paper;
$ora->pages[0] = $tst->pages;
$ora->bsize[0] = $tst->size;
$ora->time[0] = toUnixTimestamp($tst->date, $tst->time);
$param = explode('/', $tst->param);
$ora->jt[0] = substr($param[1], 3);
$ora->cp[0] = substr($param[2], 3);
$ora->ts[0] = substr($param[3], 3);
$ora->count = 1;
$ora->insert();
示例4: loadFromYml
/**
* Load method data from yaml file
* @param $file
*/
protected function loadFromYml($file)
{
$this->parser = new Parser($file);
$this->parser->load($this);
}
示例5: errorHandler
{
if ($this->errorHandlerIsActive) {
set_error_handler([$this, 'errorHandler']);
}
$this->getDom()->loadXML($string);
if ($this->errorHandlerIsActive) {
restore_error_handler();
}
return $this;
}
/**
* Custom XML lib error handler
*
* @param int $errorNo
* @param string $errorStr
* @param string $errorFile
* @param int $errorLine
* @throws \Magento\Framework\Exception\LocalizedException
* @return void
*/
public function errorHandler($errorNo, $errorStr, $errorFile, $errorLine)
{
if ($errorNo != 0) {
$message = "{$errorStr} in {$errorFile} on line {$errorLine}";
}
}
}
$Parser = new Parser();
$Parser->load('welcome.xml');
$data = $Parser->xmlToArray();
print_r($data['page']);