- 授权协议: MIT
- 开发语言: PHP
- 操作系统: 跨平台
- 软件首页: https://github.com/Microsoft/tolerant-php-parser
- 软件文档: https://github.com/Microsoft/tolerant-php-parser
软件介绍
这是一个早期的 PHP 解析器,相当于实现了 PHP 对 PHP 脚本的解析。
示例代码:
<?php
// Autoload required classes
require "vendor/autoload.php";
// Instantiate new parser instance
$parser = new PhpParser\Parser();
// Return and print an AST from string contents
$astNode = $parser->parseSourceFile('<?php /* comment */ echo "hi!"');
var_dump($astNode);
// Gets and prints errors from AST Node. The parser handles errors gracefully,
// so it can be used in IDE usage scenarios (where code is often incomplete).
$errors = PhpParser\Utilities::getDiagnostics($astNode);
var_dump(iterator_to_array($errors));
// Traverse all Node descendants of $astNode
foreach ($astNode->getDescendantNodes() as $descendant) {
if ($descendant instanceof \PhpParser\Node\StringLiteral) {
// Print the Node text (without whitespace or comments)
var_dump($descendant->getText());
// All Nodes link back to their parents, so it's easy to navigate the tree.
$grandParent = $descendant->getParent()->getParent();
var_dump($grandParent->getNodeKindName());
// The AST is fully-representative, and round-trippable to the original source.
// This enables consumers to build reliable formatting and refactoring tools.
var_dump($grandParent->getLeadingCommentAndWhitespaceText());
}
// In addition to retrieving all children or descendants of a Node,
// Nodes expose properties specific to the Node type.
if ($descendant instanceof \PhpParser\Node\Expression\EchoExpression) {
$echoKeywordStartPosition = $descendant->echoKeyword->getStartPosition();
// To cut down on memory consumption, positions are represented as a single integer
// index into the document, but their line and character positions are easily retrieved.
$lineCharacterPosition = \PhpParser\Utilities::getLineCharacterPositionFromPosition(
$echoKeywordStartPosition
);
echo "line: $lineCharacterPosition->line, character: $lineCharacterPosition->character";
}
}
The Four
Scott Galloway / Portfolio / 2017-10-3 / USD 28.00
NEW YORK TIMES BESTSELLER USA TODAY BESTSELLER Amazon, Apple, Facebook, and Google are the four most influential companies on the planet. Just about everyone thinks they know how they got there.......一起来看看 《The Four》 这本书的介绍吧!
图片转BASE64编码
在线图片转Base64编码工具
正则表达式在线测试
正则表达式在线测试
