php如何读取文件夹下所有网页标题

53次阅读
没有评论

共计 484 个字符,预计需要花费 2 分钟才能阅读完成。

要读取文件夹下所有网页标题,可以使用以下步骤:

  1. 使用 PHP 的 glob() 函数获取文件夹中的所有网页文件。例如,假设网页文件都是以 .html.htm 结尾的,可以使用以下代码获取文件列表:
$files = glob('path/to/folder/*.html');
$files += glob('path/to/folder/*.htm');
  1. 使用循环遍历文件列表,逐个打开网页文件,并使用正则表达式获取标题内容。可以使用 file_get_contents() 函数读取文件内容,然后使用正则表达式提取标题。
foreach ($files as $file) {$html = file_get_contents($file);
preg_match("/(.*?)/i", $html, $matches);
$title = $matches[1];
echo $title;
}</code></pre>
<p> 注意:这里的正则表达式仅适用于简单的网页,如果网页结构复杂,可能需要更复杂的表达式来匹配标题。同时,这种方法只能获取每个文件的第一个标题,如果一个网页文件中有多个标题,可能需要进行进一步的处理。</p>
</p>
<p> 丸趣 TV 网 – 提供最优质的资源集合!</p>
                                                    </div>
                                                <div class="t-separator c-sub t-sm mt30">正文完</div>
                                                <div class="footer-info puock-text mt20">
                            <div class="mt20 tags"><a href="https://www.wanqutv.com/tag/file/" class="pk-badge pk-badge-sm mr5 mb10"><i class="fa-solid fa-tag"></i> file</a><a href="https://www.wanqutv.com/tag/html/" class="pk-badge pk-badge-sm mr5 mb10"><i class="fa-solid fa-tag"></i> html</a><a href="https://www.wanqutv.com/tag/%e6%a0%87%e9%a2%98/" class="pk-badge pk-badge-sm mr5 mb10"><i class="fa-solid fa-tag"></i> 标题</a><a href="https://www.wanqutv.com/tag/%e7%bd%91%e9%a1%b5/" class="pk-badge pk-badge-sm mr5 mb10"><i class="fa-solid fa-tag"></i> 网页</a><a href="https://www.wanqutv.com/tag/%e7%bd%91%e9%a1%b5%e6%96%87%e4%bb%b6/" class="pk-badge pk-badge-sm mr5 mb10"><i class="fa-solid fa-tag"></i> 网页文件</a></div>                            <div class="p-flex-sbc mt20 t-sm">
                                <div>
                                    <span>发表至:</span><a  class=" mr5" href="https://www.wanqutv.com/category/itcode/php/"><i class="fa-regular fa-folder-open"></i> PHP</a>                                </div>
                                <div>
                                    <span class="c-sub"><i class="fa-regular fa-clock"></i> 2023-12-13</span>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="mt15 post-action-panel">
    <div class="post-action-content">
        <div class="d-flex justify-content-center w-100 c-sub">
            <div class="circle-button puock-bg text-center "
                 id="post-like" data-id="120791">
                <i class="fa-regular fa-thumbs-up t-md"></i> <span
                        class="t-sm"></span></div>
                            <div class="circle-button puock-bg text-center pk-modal-toggle"
                     title="海报" data-no-title data-no-padding data-once-load="true"
                     data-url="https://www.wanqutv.com/wp-admin/admin-ajax.php?action=pk_poster&id=120791"
                ><i class="fa-regular fa-images"></i></div>
                                    <div class="circle-button puock-bg text-center pk-modal-toggle"
                 title="分享" data-once-load="true"
                 data-url="https://www.wanqutv.com/wp-admin/admin-ajax.php?action=pk_ajax_dialog_post_share&id=120791">
                <i class="fa fa-share-from-square t-md"></i></div>
            <div class="ls">
                <div class="circle-button puock-bg text-center post-menu-toggle post-menus-box"><i
                            class="fa fa-bars t-md"></i></div>
            </div>
        </div>
    </div>
</div>
                </div>
                                                    <div class="p-block p-flex-sc">
                        <div class="mr-3 p-flex-sk-0">
                            <img class="md-avatar mt-1"
                                 src="https://cravatar.cn/avatar/582794e3ff32e56ad60dd5c9f330ca35?s=96&d=monsterid&r=r"
                                 alt="丸趣"
                                 title="丸趣">
                        </div>
                        <div class="puock-text t-md">
                                                            <div>
                                    <span class="font-weight-bold">版权声明:</span><span>本站原创文章,由</span>
                                    <a class="a-link"
                                       href="https://www.wanqutv.com/author/wanquadmin/">丸趣 </a>2023-12-13发表,共计484字。                                </div>
                                <div class="mt-2">
                                    <span class="font-weight-bold c-sub">转载说明:</span><span
                                            class="c-sub">除特殊说明外本站除技术相关以外文章皆由网络搜集发布,转载请注明出处。</span>
                                </div>
                                                    </div>
                    </div>
                                                <!--内页中-->
                                    
            <div class="p-block pb-0">
                <div class="row puock-text post-relevant">
                                            <a  href="https://www.wanqutv.com/itcode/php/121200.html"
                                                     class="col-6 col-md-3 post-relevant-item ww">
                            <!--                    -->                            <div style="background:url('https://www.wanqutv.com/wp-content/themes/wordpress-theme-puock-2.7.6/timthumb.php?w=160&h=140&a=c&zc=1&q=90&src=https://www.wanqutv.com/wp-content/themes/wordpress-theme-puock-2.7.6/assets/img/random/3.jpg')">
                                <div class="title">php操作redis队列的方法是什么</div>
                            </div>
                        </a>
                                                <a  href="https://www.wanqutv.com/itcode/php/147220.html"
                                                     class="col-6 col-md-3 post-relevant-item ww">
                            <!--                    -->                            <div style="background:url('https://www.wanqutv.com/wp-content/themes/wordpress-theme-puock-2.7.6/timthumb.php?w=160&h=140&a=c&zc=1&q=90&src=https://www.wanqutv.com/wp-content/themes/wordpress-theme-puock-2.7.6/assets/img/random/2.jpg')">
                                <div class="title">PHP数组中怎么用array</div>
                            </div>
                        </a>
                                                <a  href="https://www.wanqutv.com/itcode/php/121998.html"
                                                     class="col-6 col-md-3 post-relevant-item ww">
                            <!--                    -->                            <div style="background:url('https://www.wanqutv.com/wp-content/themes/wordpress-theme-puock-2.7.6/timthumb.php?w=160&h=140&a=c&zc=1&q=90&src=https://www.wanqutv.com/wp-content/themes/wordpress-theme-puock-2.7.6/assets/img/random/8.jpg')">
                                <div class="title">php如何判断输入的是否是数字</div>
                            </div>
                        </a>
                                                <a  href="https://www.wanqutv.com/itcode/php/153931.html"
                                                     class="col-6 col-md-3 post-relevant-item ww">
                            <!--                    -->                            <div style="background:url('https://www.wanqutv.com/wp-content/themes/wordpress-theme-puock-2.7.6/timthumb.php?w=160&h=140&a=c&zc=1&q=90&src=https://www.wanqutv.com/wp-content/themes/wordpress-theme-puock-2.7.6/assets/img/random/1.jpg')">
                                <div class="title">php中的file</div>
                            </div>
                        </a>
                                        </div>
            </div>

                                        
<div class="p-block p-lf-15">
    <div class="row text-center pd-links single-next-or-pre t-md ">
        <div class="col-6 p-border-r-1 p-0">
                            <a href="https://www.wanqutv.com/itcode/java/120790.html" rel="prev"><div class='abhl puock-text'><p class='t-line-1'>java怎么读取文件并输出文件流</p><span>上一篇</span></div></a>                    </div>
        <div class="col-6 p-0">
                            <a href="https://www.wanqutv.com/itcode/python/120794.html" rel="next"><div class='abhl puock-text'><p class='t-line-1'>python怎么创建类对象数组</p><span>下一篇</span></div></a>                    </div>
    </div>
</div>
                                    <!--评论上方-->
    <div class="p-block" id="comments">
        <div>
            <span class="t-lg border-bottom border-primary puock-text pb-2"><i
                        class="fa-regular fa-comments mr-1"></i>评论(没有评论)</span>
        </div>
                                    <div class="mt20 clearfix" id="comment-form-box">
                    <form class="mt10" id="comment-form" method="post"
                          action="https://www.wanqutv.com/wp-admin/admin-ajax.php?action=comment_ajax">
                        <div class="form-group">
                            <textarea placeholder="世界这么大发表一下你的看法~" id="comment" name="comment"
                                      class="form-control form-control-sm t-sm" rows="4"></textarea>
                        </div>
                        <div class="row row-cols-1 comment-info">
                                                                                        <input type="text" value="0" hidden name="comment-logged" id="comment-logged">
                                <div class="col-12 col-sm-4"><input type="text" id="comment_author"
                                                                                                name="author"
                                                                                                class="form-control form-control-sm t-sm"
                                                                                                placeholder="昵称(必填)">
                                </div>
                                <div class="col-12 col-sm-4"><input type="email" id="comment_email"
                                                                                                name="email"
                                                                                                class="form-control form-control-sm t-sm"
                                                                                                placeholder="邮箱(必填)">
                                </div>
                                <div class="col-12 col-sm-4"><input type="text" id="comment_url"
                                                                                                name="url"
                                                                                                class="form-control form-control-sm t-sm"
                                                                                                placeholder="网站">
                                </div>

                                                                                </div>

                        <input type="text" hidden name="comment_post_ID" value="120791">
                        <input type="text" hidden id="comment_parent" name="comment_parent" value="">
                        <div class="p-flex-sbc mt10">
                            <div>
                                                                                            </div>
                            <div>
                                <button id="comment-cancel" type="button"
                                        class="btn btn-outline-dark d-none btn-ssm">取消</button>
                                <button id="comment-smiley" class="btn btn-outline-secondary btn-ssm pk-modal-toggle" type="button"
                                        title="表情" data-once-load="true"
                                        data-url="https://www.wanqutv.com/wp-admin/admin-ajax.php?action=pk_ajax_dialog_smiley">
                                    <i class="fa-regular fa-face-smile t-md"></i></button>
                                <button id="comment-submit" type="submit" class="btn btn-primary btn-ssm"><i
                                            class="fa-regular fa-paper-plane"></i> 发布评论                                </button>
                            </div>
                        </div>
                    </form>
                </div>
                                        <div id="comment-ajax-load" class="text-center mt20 d-none">
                <div class="pk-skeleton _comment"><div class="_h"><div class="_avatar"></div>
                <div class="_info"><div class="_name"></div><div class="_date"></div></div></div><div class="_text"><div></div><div></div><div></div></div></div><div class="pk-skeleton _comment"><div class="_h"><div class="_avatar"></div>
                <div class="_info"><div class="_name"></div><div class="_date"></div></div></div><div class="_text"><div></div><div></div><div></div></div></div><div class="pk-skeleton _comment"><div class="_h"><div class="_avatar"></div>
                <div class="_info"><div class="_name"></div><div class="_date"></div></div></div><div class="_text"><div></div><div></div><div></div></div></div>            </div>
                <div id="post-comments">
            
            <div class="mt20 p-flex-s-right" data-no-instant>
                <ul class="pagination comment-ajax-load">
                                    </ul>
            </div>

        </div>
    </div>
                            </div>
                <div id="sidebar" class="animated fadeInRight col-lg-4 d-none d-lg-block">
        <div class="sidebar-main">
                    <div class="p-block">
                        <div>
                <span class="t-lg border-bottom border-primary
                puock-text pb-2"><i class="fa fa-search mr-1"></i>站内搜索</span>
            </div>
                        <div class="mt20">
                <form class="global-search-form" action="https://www.wanqutv.com" method="get">
                    <div class="input-group">
                        <input type="text" name="s" class="form-control t-md" placeholder="输入关键字回车搜索">
                    </div>
                </form>
            </div>
        </div>
   
        <div class="pk-widget p-block ">
                            <div>
                <span class="t-lg border-bottom border-primary
                puock-text pb-2"><i class="fa fa-chart-simple mr-1"></i>最新文章</span>
                </div>
                        <div class="mt20">

        </div></div>
        <div class="pk-widget p-block ">
                            <div>
                <span class="t-lg border-bottom border-primary
                puock-text pb-2"><i class="czs-comment-l mr-1"></i>最新留言</span>
                </div>
                        <div class="mt20">

                <div class="min-comments t-md">
                         <div class="comment t-md t-line-1">
                <img src='https://www.wanqutv.com/wp-content/themes/wordpress-theme-puock-2.7.6/assets/img/z/load.svg' class='lazy min-avatar' data-src='https://cravatar.cn/avatar/04ac1f159c897743eab51f48590a423d?s=96&d=monsterid&r=r' alt="六了个六">
                <a class="puock-link"  href="https://www.wanqutv.com/wangzhanzhizuo/1316.html#comment-14">
                <span class="ta3 link-hover">六了个六</span></a>
                <span class="c-sub t-w-400">6666</span>
            </div>
                         <div class="comment t-md t-line-1">
                <img src='https://www.wanqutv.com/wp-content/themes/wordpress-theme-puock-2.7.6/assets/img/z/load.svg' class='lazy min-avatar' data-src='https://cravatar.cn/avatar/04ac1f159c897743eab51f48590a423d?s=96&d=monsterid&r=r' alt="路过的小朋友">
                <a class="puock-link"  href="https://www.wanqutv.com/seo/259.html#comment-6">
                <span class="ta3 link-hover">路过的小朋友</span></a>
                <span class="c-sub t-w-400">突突突</span>
            </div>
                    </div>
        </div></div>
        <div class="pk-widget p-block ">
                            <div>
                <span class="t-lg border-bottom border-primary
                puock-text pb-2"><i class="czs-user-l mr-1"></i>读者墙</span>
                </div>
                        <div class="mt20">

                <div class="row puock-text">
                         <div class="col col-12 col-lg-6 pl-0">
                 <div class="p-2 text-truncate text-nowrap">
                    <a href="https://www.wanqutv.com/wp-content/themes/wordpress-theme-puock-2.7.6/inc/go.php?to=aHR0cHM6Ly90Lm1lLytIRnhrNXZsVXZHRXpNMlpp" class="a-link"
                        target="_blank" rel="nofollow">
                        <img src='https://www.wanqutv.com/wp-content/themes/wordpress-theme-puock-2.7.6/assets/img/z/load.svg' class='lazy md-avatar' data-src='https://cravatar.cn/avatar/3ecd08db6dcc7364a728f93b621e34e2?s=96&d=monsterid&r=r' alt="Jessejap">
                        <span class="t-sm">Jessejap</span>
                    </a>
                </div>
            </div>
                         <div class="col col-12 col-lg-6 pl-0">
                 <div class="p-2 text-truncate text-nowrap">
                    <a href="https://www.wanqutv.com/wp-content/themes/wordpress-theme-puock-2.7.6/inc/go.php?to=aHR0cHM6Ly9hdWd1c3RkaWdpdGFsLnJ1Lw==" class="a-link"
                        target="_blank" rel="nofollow">
                        <img src='https://www.wanqutv.com/wp-content/themes/wordpress-theme-puock-2.7.6/assets/img/z/load.svg' class='lazy md-avatar' data-src='https://cravatar.cn/avatar/4b3786887e552f9282c4e6ab6aca0f5c?s=96&d=monsterid&r=r' alt="Jessejap">
                        <span class="t-sm">Jessejap</span>
                    </a>
                </div>
            </div>
                         <div class="col col-12 col-lg-6 pl-0">
                 <div class="p-2 text-truncate text-nowrap">
                    <a href="https://www.wanqutv.com/wp-content/themes/wordpress-theme-puock-2.7.6/inc/go.php?to=aHR0cHM6Ly9hcmVuZGFrYXRlcmEucHJv" class="a-link"
                        target="_blank" rel="nofollow">
                        <img src='https://www.wanqutv.com/wp-content/themes/wordpress-theme-puock-2.7.6/assets/img/z/load.svg' class='lazy md-avatar' data-src='https://cravatar.cn/avatar/35160bec1780d58b2432099aafff32b9?s=96&d=monsterid&r=r' alt="Robertspook">
                        <span class="t-sm">Robertspook</span>
                    </a>
                </div>
            </div>
                         <div class="col col-12 col-lg-6 pl-0">
                 <div class="p-2 text-truncate text-nowrap">
                    <a href="https://www.wanqutv.com/wp-content/themes/wordpress-theme-puock-2.7.6/inc/go.php?to=aHR0cHM6Ly9rcmEtMjUuY2M=" class="a-link"
                        target="_blank" rel="nofollow">
                        <img src='https://www.wanqutv.com/wp-content/themes/wordpress-theme-puock-2.7.6/assets/img/z/load.svg' class='lazy md-avatar' data-src='https://cravatar.cn/avatar/7c8765d7b9affe5e3494e6f1dda00473?s=96&d=monsterid&r=r' alt="Davogest">
                        <span class="t-sm">Davogest</span>
                    </a>
                </div>
            </div>
                         <div class="col col-12 col-lg-6 pl-0">
                 <div class="p-2 text-truncate text-nowrap">
                    <a href="https://www.wanqutv.com/wp-content/themes/wordpress-theme-puock-2.7.6/inc/go.php?to=aHR0cHM6Ly9rZTF0YXJvLmNvbS9jcnlwdG8v" class="a-link"
                        target="_blank" rel="nofollow">
                        <img src='https://www.wanqutv.com/wp-content/themes/wordpress-theme-puock-2.7.6/assets/img/z/load.svg' class='lazy md-avatar' data-src='https://cravatar.cn/avatar/6f026418dcc9354d534e7d357c2e6329?s=96&d=monsterid&r=r' alt="crypto7Ses">
                        <span class="t-sm">crypto7Ses</span>
                    </a>
                </div>
            </div>
                         <div class="col col-12 col-lg-6 pl-0">
                 <div class="p-2 text-truncate text-nowrap">
                    <a href="https://www.wanqutv.com/wp-content/themes/wordpress-theme-puock-2.7.6/inc/go.php?to=aHR0cHM6Ly93d3cubm8tc2l0ZS5jb20=" class="a-link"
                        target="_blank" rel="nofollow">
                        <img src='https://www.wanqutv.com/wp-content/themes/wordpress-theme-puock-2.7.6/assets/img/z/load.svg' class='lazy md-avatar' data-src='https://cravatar.cn/avatar/031afcd465505505f34335f76efe6f3f?s=96&d=monsterid&r=r' alt="Mike Blare">
                        <span class="t-sm">Mike Blare</span>
                    </a>
                </div>
            </div>
                         <div class="col col-12 col-lg-6 pl-0">
                 <div class="p-2 text-truncate text-nowrap">
                    <a href="https://www.wanqutv.com/wp-content/themes/wordpress-theme-puock-2.7.6/inc/go.php?to=aHR0cHM6Ly9rcmEtMjUuY2M=" class="a-link"
                        target="_blank" rel="nofollow">
                        <img src='https://www.wanqutv.com/wp-content/themes/wordpress-theme-puock-2.7.6/assets/img/z/load.svg' class='lazy md-avatar' data-src='https://cravatar.cn/avatar/79992f4cba04431bb5864751394b1bf5?s=96&d=monsterid&r=r' alt="Davogest">
                        <span class="t-sm">Davogest</span>
                    </a>
                </div>
            </div>
                         <div class="col col-12 col-lg-6 pl-0">
                 <div class="p-2 text-truncate text-nowrap">
                    <a href="javascript:void(0)" class="a-link"
                         rel="nofollow">
                        <img src='https://www.wanqutv.com/wp-content/themes/wordpress-theme-puock-2.7.6/assets/img/z/load.svg' class='lazy md-avatar' data-src='https://cravatar.cn/avatar/06a385d54e47ae74a0c3f39a32652dbb?s=96&d=monsterid&r=r' alt="XRSes">
                        <span class="t-sm">XRSes</span>
                    </a>
                </div>
            </div>
                         <div class="col col-12 col-lg-6 pl-0">
                 <div class="p-2 text-truncate text-nowrap">
                    <a href="https://www.wanqutv.com/wp-content/themes/wordpress-theme-puock-2.7.6/inc/go.php?to=aHR0cHM6Ly92ZHZhZHZlbnR1cmUuY29tLw==" class="a-link"
                        target="_blank" rel="nofollow">
                        <img src='https://www.wanqutv.com/wp-content/themes/wordpress-theme-puock-2.7.6/assets/img/z/load.svg' class='lazy md-avatar' data-src='https://cravatar.cn/avatar/e2c37a7b28c2619b25218a4b719bae69?s=96&d=monsterid&r=r' alt="Jerrywed">
                        <span class="t-sm">Jerrywed</span>
                    </a>
                </div>
            </div>
                         <div class="col col-12 col-lg-6 pl-0">
                 <div class="p-2 text-truncate text-nowrap">
                    <a href="javascript:void(0)" class="a-link"
                         rel="nofollow">
                        <img src='https://www.wanqutv.com/wp-content/themes/wordpress-theme-puock-2.7.6/assets/img/z/load.svg' class='lazy md-avatar' data-src='https://cravatar.cn/avatar/68916b68f105ce8e80612d4cc99d1dbf?s=96&d=monsterid&r=r' alt="HarryLah">
                        <span class="t-sm">HarryLah</span>
                    </a>
                </div>
            </div>
                    </div>
        </div></div>        </div>
    </div>
        </div>
        <!--全局下方-->
    </div>



    <div id="post-menus" class="post-menus-box">
        <div id="post-menu-state" class="post-menu-toggle" title="打开或关闭文章目录">
            <i class="puock-text ta3 fa fa-bars"></i>
        </div>
        <div id="post-menu-content" class="animated slideInRight mini-scroll">
            <div id="post-menu-head">
            </div>
            <div id="post-menu-content-items"></div>
        </div>
    </div>
<!--返回顶部和底部-->
<div id="rb-float-actions">
    <div data-to-area="#comments" class="p-block"><i class="fa-regular fa-comments puock-text"></i></div>    <div data-to="top" class="p-block"><i class="fa fa-arrow-up puock-text"></i></div>
    <div data-to="bottom" class="p-block"><i class="fa fa-arrow-down puock-text"></i></div>
</div>
<footer id="footer">
    <div class="container">
        <div class="row row-cols-md-1">
                                </div>
    </div>
    <div class="mt20 text-center t-md">
        <div class="info">
            免责声明:本站分享资源部分来源互联网,仅供学习交流,商业用途请购买正版,否则版权纠纷由用户承担,丸趣TV不承担连带责任。如有侵权请联系博主我们尽快删除处理!</br>
Copyright @ 2014-2023| <a href="https://wanqutv.com" target="_blank">丸趣TV</a> All rights reserved.Theme By Puock. <a href="http://beian.miit.gov.cn" rel="nofollow" target="_blank">豫ICP备16006851号-5</a>
        </div>
    </div>
    </div>
</footer>

</div>
<div id="gt-validate-box"></div>
<script data-instant>var puock_metas ={"home":"https:\/\/www.wanqutv.com","vd_comment":false,"vd_gt_id":"","vd_type":"img","use_post_menu":true,"is_single":true,"is_pjax":true,"main_lazy_img":true,"link_blank_open":true,"async_view_id":120791,"mode_switch":true,"async_view_generate_time":1734906644};</script>
<script type="text/javascript" data-no-instant src="https://www.wanqutv.com/wp-content/themes/wordpress-theme-puock-2.7.6/assets/dist/js/libs.min.js?ver=6.7.1" id="puock-libs-js"></script>
<script type="text/javascript" data-no-instant src="https://www.wanqutv.com/wp-content/themes/wordpress-theme-puock-2.7.6/assets/libs/layer/layer.js?ver=6.7.1" id="puock-layer-js"></script>
<script type="text/javascript" data-no-instant src="https://www.wanqutv.com/wp-content/themes/wordpress-theme-puock-2.7.6/assets/libs/spark-md5.min.js?ver=6.7.1" id="puock-spark-md5-js"></script>
<script type="text/javascript" data-no-instant src="https://www.wanqutv.com/wp-content/themes/wordpress-theme-puock-2.7.6/assets/libs/html2canvas.min.js?ver=6.7.1" id="puock-html2canvas-js"></script>
<script type="text/javascript" data-no-instant src="https://www.wanqutv.com/wp-content/themes/wordpress-theme-puock-2.7.6/assets/dist/js/puock.min.js?ver=6.7.1" id="puock-js"></script>
<script type="text/javascript" src="https://www.wanqutv.com/wp-content/plugins/WordPress百度搜索推送管理插件专业版/assets/baidu_push.js" id="wb-baidu-push-js"></script>
    
<script>console.log('共计查询SQL:58次,耗时:0.861秒');</script></body>
</html>