正则过滤数据学习笔记(①)

 //$noTagsText = ' \n     \n     \n         \n         \n             \n                 \n
        //                    Total pending orders                 \n             \n             \n                2             \n         \n         \n                      \n                 \n         \n         \n         \n             \n     \n            Today     \n     \n        2     \n \n \n     \n            Yesterday     \n     \n        0     \n \n \n     \n        Older     \n     \n        0     \n \n             \n                 Current Daily Order Volume Limitation \n                                     \n                        10000                     \n                             \n         \n         \n     \n \n\n             \n     \n         \n         \n             \n                 \n                    your rating                 \n             \n             \n                4.0             \n         \n         \n              \n         \n         \n         \n         \n                                                         \n                                     \n                        Cancellation rate                                                 \n                         Excellent \n                     \n                     \n                         0%   \n                     \n                                 \n                                                             \n                                     \n                        Quality return rate                                                 \n                         Excellent \n                     \n                     \n                         0%   \n                     \n                                 \n                                                             \n                                     \n                        Average customer rating                                                 \n                         Bad \n                     \n                     \n                         2.8   \n                     \n                                 \n                                                         \n                     \n                         \n                     \n                      \n                 \n                     \n         \n     \n \n    \n     \n         \n             \n             \n                 \n                     \n                        Best Selling Product Sales Contribution                     \n                 \n                 \n                    68%                 \n             \n             \n                  \n             \n             \n             \n             \n                                                     \n                         \n                            Best selling products low stock level                         \n                         0 \n                     \n                                                                 \n                     Total out of stock \n                     49820 \n                 \n                                                                     \n                          \n                          \n                     \n                                     \n                          \n                          \n                     \n                             \n             \n         \n     \n     \n     \n         \n         \n             \n                 \n                    New product creation in the last 14 days                 \n                 \n                      \n                 \n             \n             \n                726             \n         \n         \n         \n         \n             \n                 Rejected products (poor quality) \n                 \n                        13951                 \n             \n             \n                 Rejected products (image missing) \n                 \n                    51307                 \n             \n             \n                 Approved products \n                 \n                        317087                 \n             \n             \n                 Pending products \n                 \n                        19                 \n             \n         \n         \n     \n       \n \n';

        // $noTagsText = preg_replace("/[\r\n\t]+/", PHP_EOL, $noTagsText);
        // $noTagsText = preg_replace("/[\r\n\t]+/", PHP_EOL, $noTagsText);
        // $noTagsText = preg_replace("/ +/", " ", $noTagsText);
        // $noTagsText = str_replace('\n', PHP_EOL, $noTagsText);
        /*$noTagsText = preg_replace("/<style.*?>.*?<\/style>/is", " ", $noTagsText);       //过滤css*/
        /*$noTagsText = preg_replace("/<script.*?>.*?<\/script>/is", " ", $noTagsText);     //过滤script*/
        // $noTagsText = preg_replace("/<!--.*?-->/is", " ", $noTagsText);                   //过滤html注释
        /*$noTagsText = preg_replace("/<\/?[a-zA-Z]+.*?>/is", " ", $noTagsText);            //过滤掉所有的html标签*/
        // $noTagsText = preg_replace("/&[a-zA-Z]{2,};/", " ", $noTagsText);                 //过滤html实体
        //换行符 制表符替换为空格
        // $noTagsText = preg_replace("/[\r\n\t]/", PHP_EOL, $noTagsText);
        // $noTagsText = strip_tags($noTagsText);


        // $noTagsText = preg_replace_callback(
        //     ['/\\\\n/', '/ +/'],
        //     function ($matches) {
        //         if (reset($matches) == PHP_EOL) {
        //             return '';
        //         } else {
        //             return ' ';
        //         }
        //     },
        //     $noTagsText
        // );
        //
        // var_export($noTagsText);
        //
        // return false;
        $noTagsText = '<div class=\"home-stats-container\">\n    <div class=\"col-lg-3 col-sm-6 col-md-6\">\n    <div class=\"home-stats-block home-stats-color-blue\">\n        <!-- Header -->\n        <a class=\"home-stats-header-container\" href=\"/order/#!/reset-filters\">\n            <span class=\"home-stats-header--row\">\n                <span class=\"home-stats-header-text\">\n                    Total pending orders                </span>\n            </span>\n            <div class=\"home-stats-header-body\">\n                2            </div>\n        </a>\n        <span class=\"js-tooltip\" data-toggle=\"tooltip\" data-placement=\"top\"\n              data-original-title=\"Display of total order amount which is pending since the listed time.\">\n                    <i class=\"font-icon icon-info-circled-alt\"></i>\n                </span>\n        <!-- Header -->\n        <!-- Rows -->\n        <div class=\"home-stats-body-container\">\n            <a id=\"js-pending-orders-today\" class=\"home-stats-body-row\" href=\"/order/index/index/fromDate/2022-07-21/#!/reset-filters\">\n    <span class=\"details-cell\">\n            Today    </span>\n    <span class=\"numbers-cell\">\n        2    </span>\n</a>\n<a id=\"js-pending-orders-yesterday\" class=\"home-stats-body-row\" href=\"/order/index/index/fromDate/2022-07-20/toDate/2022-07-20/#!/reset-filters\">\n    <span class=\"details-cell\">\n            Yesterday    </span>\n    <span class=\"numbers-cell\">\n        0    </span>\n</a>\n<a id=\"js-pending-orders-older\" class=\"home-stats-body-row\" href=\"/order/index/index/fromDate/2021-07-21/toDate/2022-07-19/#!/reset-filters\">\n    <span class=\"details-cell\">\n        Older    </span>\n    <span class=\"numbers-cell\">\n        0    </span>\n</a>\n            <a class=\"home-stats-body-row\" href=\"/order/#!/reset-filters\">\n                <span class=\"details-cell\">Current Daily Order Volume Limitation</span>\n                                    <span class=\"numbers-cell\">\n                        10000                    </span>\n                            </a>\n        </div>\n        <!-- Rows -->\n    </div>\n</div>\n\n            <div class=\"col-lg-3 col-md-6 col-sm-6\">\n    <div class=\"home-stats-block home-stats-color-orange\">\n        <!-- Header -->\n        <div class=\"home-stats-header-container\">\n            <div class=\"home-stats-header--row\">\n                <div class=\"home-stats-header-text\">\n                    your rating                </div>\n            </div>\n            <div class=\"home-stats-header-body\">\n                4.0            </div>\n        </div>\n        <a class=\"js-tooltip\" data-toggle=\"tooltip\" data-placement=\"top\" title=\"\"\n           data-original-title=\"Calculation date: 2022-07-20.\">\n            <i class=\"font-icon icon-info-circled-alt\"></i>\n        </a>\n        <!-- Header -->\n        <!-- Rows -->\n        <div class=\"home-stats-body-container\">\n                                                        <a class=\"home-stats-body-row\"\n                   href=\"/order/index/index/filteredStatus/3\"\n                >\n                                    <span class=\"details-cell\">\n                        Cancellation rate                                                <br/>\n                        <strong>Excellent</strong>\n                    </span>\n                    <span class=\"numbers-cell\">\n                        <span>0%<i\n                                    class=\"font-icon\"></i></span>\n                    </span>\n                                </a>\n                                                            <a class=\"home-stats-body-row\"\n                   href=\"/order/index/index/filteredStatus/4\"\n                >\n                                    <span class=\"details-cell\">\n                        Quality return rate                                                <br/>\n                        <strong>Excellent</strong>\n                    </span>\n                    <span class=\"numbers-cell\">\n                        <span>0%<i\n                                    class=\"font-icon\"></i></span>\n                    </span>\n                                </a>\n                                                            <div class=\"home-stats-body-row\">\n                                    <span class=\"details-cell\">\n                        Average customer rating                                                <br/>\n                        <strong>Bad</strong>\n                    </span>\n                    <span class=\"numbers-cell\">\n                        <span>2.8<i\n                                    class=\"font-icon\"></i></span>\n                    </span>\n                                </div>\n                                                        <div class=\"home-stats-body-row\">\n                    <span class=\"details-cell\">\n                        <br/>\n                    </span>\n                    <span class=\"numbers-cell\"></span>\n                </div>\n                    </div>\n        <!-- Rows -->\n    </div>\n</div>\n    \n    <div class=\"col-lg-3 col-md-6 col-sm-6\">\n        <div class=\"home-stats-block home-stats-color-purple\">\n            <!-- Header -->\n            <a class=\"home-stats-header-container\" href=\"/product/index/best-selling\">\n                <span class=\"home-stats-header--row\">\n                    <span class=\"home-stats-header-text\">\n                        Best Selling Product Sales Contribution                    </span>\n                </span>\n                <div class=\"home-stats-header-body\">\n                    68%                </div>\n            </a>\n            <a class=\"js-tooltip pull-right\" data-toggle=\"tooltip\" data-placement=\"top\" title=\"\"\n               data-original-title=\"Best Selling products are the top 20% of your shop assortment that sold the most in the past 14 days.\">\n                <i class=\"font-icon icon-info-circled-alt\"></i>\n            </a>\n            <!-- Header -->\n            <!-- Rows -->\n            <div class=\"home-stats-body-container\">\n                                                    <a class=\"home-stats-body-row\" href=\"/product/index/best-selling\">\n                        <span class=\"details-cell\">\n                            Best selling products low stock level                        </span>\n                        <span class=\"numbers-cell\">0</span>\n                    </a>\n                                                                <a class=\"home-stats-body-row\" href=\"/product/index/sold-out\">\n                    <span class=\"details-cell\">Total out of stock</span>\n                    <span class=\"numbers-cell\">49820</span>\n                </a>\n                                                                    <div class=\"home-stats-body-row\">\n                        <span class=\"details-cell\"></span>\n                        <span class=\"numbers-cell\"></span>\n                    </div>\n                                    <div class=\"home-stats-body-row\">\n                        <span class=\"details-cell\"></span>\n                        <span class=\"numbers-cell\"></span>\n                    </div>\n                            </div>\n            <!-- Rows -->\n        </div>\n    </div>\n    <div class=\"col-lg-3 col-md-6 col-sm-6\">\n    <div class=\"home-stats-block home-stats-color-green\">\n        <!-- Header -->\n        <div class=\"home-stats-header-container\">\n            <div class=\"home-stats-header--row\">\n                <div class=\"home-stats-header-text\">\n                    New product creation in the last 14 days                </div>\n                <a class=\"js-tooltip\" data-toggle=\"tooltip\" data-placement=\"top\"\n                   data-original-title=\"Overview on amount of products, which got created as well as their approval summary.\">\n                    <i class=\"font-icon icon-info-circled-alt\"></i>\n                </a>\n            </div>\n            <div class=\"home-stats-header-body\">\n                726            </div>\n        </div>\n        <!-- Header -->\n        <!-- Rows -->\n        <div class=\"home-stats-body-container\">\n            <a class=\"home-stats-body-row\" href=\"/product/index/rejected\">\n                <span class=\"details-cell\">Rejected products (poor quality)</span>\n                <span class=\"numbers-cell\">\n                        13951                </span>\n            </a>\n            <a class=\"home-stats-body-row\" href=\"/product/index/image-missing\">\n                <span class=\"details-cell\">Rejected products (image missing)</span>\n                <span class=\"numbers-cell\">\n                    51307                </span>\n            </a>\n            <a class=\"home-stats-body-row\" href=\"/product/index/active\">\n                <span class=\"details-cell\">Approved products</span>\n                <span class=\"numbers-cell\">\n                        317087                </span>\n            </a>\n            <a class=\"home-stats-body-row\" href=\"/product/index/pending\">\n                <span class=\"details-cell\">Pending products</span>\n                <span class=\"numbers-cell\">\n                        19                </span>\n            </a>\n        </div>\n        <!-- Rows -->\n    </div>\n</div>    <div class=\"clearfix\"></div>\n</div>\n';

        // $noTagsText = preg_replace("/<!--.*?-->/is", " ", $noTagsText);
        //
        $noTagsText = str_replace('\n', PHP_EOL, $noTagsText);
        $noTagsText = str_replace('\\', '', $noTagsText);
 /*$noTagsText = preg_replace("/<style.*?>.*?<\/style>/is", " ", $noTagsText);       //过滤css*/
                /*$noTagsText = preg_replace("/<script.*?>.*?<\/script>/is", " ", $noTagsText);     //过滤script*/
                // $noTagsText = preg_replace("/<!--.*?-->/is", " ", $noTagsText);                   //过滤html注释
                /*$noTagsText = preg_replace("/<\/?[a-zA-Z]+.*?>/is", " ", $noTagsText);            //过滤掉所有的html标签*/
                // $noTagsText = preg_replace("/&[a-zA-Z]{2,};/", " ", $noTagsText);                 //过滤html实体
                //换行符 制表符替换为空格
                // $noTagsText = preg_replace("/[\r\n\t]/", PHP_EOL, $noTagsText);
                // $noTagsText = strip_tags($noTagsText);

                $noTagsText = str_replace('\n', PHP_EOL, $noTagsText);   // 替换本身的  \n 字符为换行

                $noTagsText = preg_replace("/<!--.*?-->/is", "", $noTagsText);   // 去除注释

                $noTagsText = preg_replace("/[\r\n\t]/", PHP_EOL, $noTagsText);

                $noTagsText = strip_tags($noTagsText);  // 去除 标签

                $noTagsText = preg_replace("(\s+\r)", PHP_EOL, $noTagsText);  // 换行多个改为一个

                $noTagsText = preg_replace_callback(
                    ['/\\\\n/', '/ +/'],
                    function ($matches) {
                        if (reset($matches) == PHP_EOL) {
                            return '';
                        } else {
                            return ' ';
                        }
                    },
                    $noTagsText
                );

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值