PHP 正则加递归提取路径问题。

不会武功 发布于 2019/12/26 11:31
阅读 97
收藏 0

现在有以下代码。如果没有格式化是一行。这里为了方便看我给格式化一下。

<div class="treeview">
    <ul id="code_tree" class="filetree">
        <li class="expandable">
            <div class="hitarea expandable-hitarea"></div>
            <span class="folder">abc</span>
            <ul style="display: block;">
                <li class="expandable">
                    <div class="hitarea expandable-hitarea"></div>
                    <span class="folder">img</span>
                    <ul style="display: block;">
                        <li class="expandable">
                            <div class="hitarea expandable-hitarea"></div>
                            <span class="folder">product</span>
                            <ul style="display: block;">
                                <li><span class="img">product-01.jpg</span></li>
                                <li><span class="img">product-02.jpg</span></li>
                            </ul>
                        </li>
                        <li><span class="img">img-01.jpg</span></li>
                    </ul>
                </li>
                <li class="expandable">
                    <div class="hitarea expandable-hitarea"></div>
                    <span class="folder">plugins</span>
                    <ul style="display: block;">
                        <li class="expandable">
                            <div class="hitarea expandable-hitarea"></div>
                            <span class="folder">datatables</span>
                            <ul style="display: block;">
                                <li><span class="css">datatables.min.css</span></li>
                                <li><span class="js">datatables.min.js</span></li>
                            </ul>
                        </li>
                        <li class="expandable">
                            <div class="hitarea expandable-hitarea"></div>
                            <span class="folder">light-gallery</span>
                            <ul style="display: block;">
                                <li class="expandable">
                                    <div class="hitarea expandable-hitarea"></div>
                                    <span class="folder">css</span></li>
                                <li class="expandable">
                                    <div class="hitarea expandable-hitarea"></div>
                                    <span class="folder">fonts</span></li>
                            </ul>
                        </li>
                        <li class="expandable">
                            <div class="hitarea expandable-hitarea"></div>
                            <span class="folder">morris</span>
                            <ul style="display: block;">
                                <li><span class="css">morris.css</span></li>
                                <li><span class="js">morris.min.js</span></li>
                            </ul>
                        </li>

                    </ul>
                </li>
            </ul>
        </li>
        <li><span class="html">abc.html</span></li>
    </ul>
</div>

|
最终需要输出
abc.html
abc/img/product/product-01.jpg
....


你可以在这里进行代码调试。
 http://www.dooccn.com/php7/#id/0343672d07b2dd785893dd3dff67350b 
哪个大佬看看用正则加递归写一个通用的PHP代码?

加载中
0
OSC_JcgUMX
OSC_JcgUMX
正则搞这个是自找麻烦,把这片段按html或者xml解析成文档树再遍历会好一些
OSCHINA
登录后可查看更多优质内容
返回顶部
顶部