标签: php-parser

PEG语法和解析器生成器的局限性?

我很享受YARD的使用:

http://www.ootl.org/yard/

http://code.google.com/p/yardparser/

http://www.codeproject.com/KB/recipes/yard-tokenizer.aspx

我能够构建全功能计算器.我正在评估YARD做PHP解析器.请关注PEG语法和解析器生成器的局限性.非常感谢你!

peg parser-generator yard php-parser

14
推荐指数
2
解决办法
6559
查看次数

Laravel 4使用nikic phpparser:发送电子邮件时内存不足

刚刚得知Laravel内部使用了nikic phpparser.

我修改了我的代码,以便在其中一个条件下发送电子邮件并开始死亡.
PHP日志显示了这个:

[Sat Oct 03 21:18:23 2015] [错误] [client xx.xx.xx.xx] PHP致命错误:/ home/yyyy/public_html /中允许的内存大小为33554432字节(尝试分配1048576字节)供应商/ nikic/PHP的解析器/ LIB/PHPParser/NodeTraverser.php上线66,引荐:http://yyyy.com/home

我暂时增加了内存以解决问题.
但是,我想摆脱创可贴.
我看到NodeTraverser函数正在进行克隆,这会导致问题:

   protected function traverseNode(PHPParser_Node $node)
   {

    ini_set('memory_limit', '64M'); // temporary fix
    $node = clone $node;

    foreach ($node->getSubNodeNames() as $name) {
        $subNode =& $node->$name;

        if (is_array($subNode)) {
            $subNode = $this->traverseArray($subNode);
        } elseif ($subNode instanceof PHPParser_Node) {
            foreach ($this->visitors as $visitor) {
                if (null !== $return = $visitor->enterNode($subNode)) {
                    $subNode = $return;
                }
            }

            $subNode = $this->traverseNode($subNode);

            foreach ($this->visitors as $visitor) { …
Run Code Online (Sandbox Code Playgroud)

out-of-memory php-parser laravel

6
推荐指数
1
解决办法
167
查看次数

将HTML表行转换为PHP数组并将其保存到数据库中?

我正在尝试将html表行保存到php数组中,然后将数组保存在数据库中.

<form action="" method="post">
        <table class="widefat" id="theTable">
                        <thead>
                                <tr>
                                   <th>Level Identifier</th>
                                    <th>Non-logged in message</th>
                                    <th>Logged in message</th>
                                </tr>
                        </thead>
                        <tbody>

                                  <tr>
                                    <td><input type="text" value="" style="height: 19px;background-color: white;font-size:10px;"/></td>
                                    <td><textarea style="font-size:10px;" name="promo_msg_free" cols="43" rows="1">This is your custom message template</textarea></td>
                                    <td><textarea style="font-size:10px;" name="promo_msg_free" cols="43" rows="1">This is your custom message template</textarea></td>
                                  </tr>

                                   <tr>
                                    <td><input type="text" value="" style="height: 19px;background-color: white;font-size:10px;"/></td>
                                    <td><textarea style="font-size:10px;" name="promo_msg_free" cols="43" rows="1"></textarea></td>
                                    <td><textarea style="font-size:10px;" name="promo_msg_free" cols="43" rows="1"></textarea></td>
                                  </tr>

                        </tbody>    
                    </table> 
                </form>
Run Code Online (Sandbox Code Playgroud)

我如何检索每个行数据并将其保存到数组元素,最后我将数组保存到数据库?谢谢

html php html-parsing php-parser

3
推荐指数
1
解决办法
1万
查看次数

使用PHP解析Web页面内容

我认为这是一个简单的问题,但我已经做了我所知道的但仍然没有工作.我想从这个链接获得输出:

http://api.microsofttranslator.com/V2/Ajax.svc/Translate?text=siapa+rektor+ipb&appId=58C40548A812ED699C35664525D8A8104D3006D2&from=id&to=en

您可以在浏览器上粘贴并查看它.有一些文字输出.我试过PHP中的一些函数,比如file_get_contents和curl.我没有使用ajax或JavaScript,因为我不熟悉它.最后,我正在与XAMPP合作.

php curl file file-get-contents php-parser

2
推荐指数
1
解决办法
9358
查看次数

如何从php解析的html中删除除允许列表之外的所有标记

我在php中解析html,因为我无法控制原始内容,我想删除样式和不必要的标签,同时仍保留内容和标签的简短列表,即:

p,img,iframe(也许还有其他一些)

我知道我可以删除一个给定的标签(参见我在下面使用的代码),但由于我不一定知道它们可能是什么标签,而且我不想创建一个巨大的可能列表,我会喜欢除了我允许的列表之外能够删除所有内容.

function DOMRemove(DOMNode $from) {
    $sibling = $from->firstChild;

    do {
        $next = $sibling->nextSibling;
        $from->parentNode->insertBefore($sibling, $from);
    } while ($sibling = $next);

    $from->parentNode->removeChild($from);
}

$dom = new DOMDocument;
$dom->loadHTML($html);

$nodes = $dom->getElementsByTagName('span');
Run Code Online (Sandbox Code Playgroud)

php dom html-parsing domdocument php-parser

1
推荐指数
1
解决办法
2522
查看次数

使用REGEX查找PHP

我需要一个可以在文件中找到PHP代码块的REGEX.例如:

    <? print '<?xml version="1.0" encoding="UTF-8"?>';?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
    <head>
        <?php echo "stuff"; ?>
    </head>
    <html>
Run Code Online (Sandbox Code Playgroud)

当REGEX解析时会返回:

array(
    "<? print '<?xml version=\"1.0\" encoding="UTF-8"?>';?>",
    "<? echo \"stuff\"; ?>"
);
Run Code Online (Sandbox Code Playgroud)

您可以假设PHP有效.

php regex parsing php-parser

0
推荐指数
1
解决办法
156
查看次数

如何使用 SCEditor 将 bbcode 转换为 html

我在论坛中使用SCEditor 。我设法将 bbcodes 插入数据库。但是当我尝试在页面中显示代码时,bbcodes 显示时没有样式。没有html,没有样式。只有坏的 bbcodes。我在其文档页面中调查了很长时间,但没有找到任何 php 解析器。这是屏幕截图。在此输入图像描述请问,你能帮我吗,如何在 PHP 中将 bbcode 解析为 html?

php editor bbcode php-parser

0
推荐指数
1
解决办法
4061
查看次数