从通用Href字符串数组中过滤入站URL

时间:2018-11-01 17:03:43

标签: php arrays parsing url filtering

我有一个网页的 href属性收集的字符串数组。 现在,我需要过滤该数组,并获得一个新的入站URL 数组,这些URL指向我收集它们的同一域。 考虑到字符串应该为:

  • 普通HTTP或HTTPs网址
  • JavaScript
  • 入站URL但未设置主机(例如/my-folder/my-file.php)
  • 同一页面锚点#my-anchor(与出站链接http://my-domain.com/#my-anchor中的锚点不同)
  • 其他情况

我正在寻找一个考虑所有可能情况或本机PHP解决方案的过滤器回调。我试图不使用像http://url.thephpleague.com/这样的外部库。

我找到了这些实用程序:

示例数组,来自两个不同域的2个

array (
  0 => '//www.w3schools.com',
  1 => 'javascript:void(0);',
  2 => '/default.asp',
  3 => '/html/default.asp',
  4 => '/css/default.asp',
  5 => '/js/default.asp',
  6 => '/sql/default.asp',
  7 => '/php/default.asp',
  8 => '/bootstrap/default.asp',
  9 => '/howto/default.asp',
  10 => '/jquery/default.asp',
  11 => '/w3css/default.asp',
  12 => '/python/default.asp',
  13 => '/xml/default.asp',
  14 => 'javascript:void(0);',
  15 => 'javascript:void(0);',
  16 => 'javascript:void(0);',
  17 => '/forum/default.asp',
  18 => 'javascript:void(0);',
  19 => 'javascript:void(0);',
  20 => '/html/default.asp',
  21 => '/css/default.asp',
  22 => '/w3css/default.asp',
  23 => '/colors/default.asp',
  24 => '/bootstrap/default.asp',
  25 => '/bootstrap4/default.asp',
  26 => '/graphics/default.asp',
  27 => '/icons/default.asp',
  28 => '/howto/default.asp',
  29 => '/js/default.asp',
  30 => '/jquery/default.asp',
  31 => '/angular/default.asp',
  32 => '/js/js_json_intro.asp',
  33 => '/js/js_ajax_intro.asp',
  34 => '/w3js/default.asp',
  35 => '/sql/default.asp',
  36 => '/php/default.asp',
  37 => '/python/default.asp',
  38 => '/java/default.asp',
  39 => '/asp/default.asp',
  40 => '/nodejs/default.asp',
  41 => '/nodejs/nodejs_raspberrypi.asp',
  42 => '/w3css/w3css_templates.asp',
  43 => '/browsers/default.asp',
  44 => '/cert/default.asp',
  45 => '/tryit/default.asp',
  46 => '/whatis/default.asp',
  47 => '/xml/default.asp',
  48 => '/xml/ajax_intro.asp',
  49 => '/xml/dom_intro.asp',
  50 => '/xml/xml_dtd_intro.asp',
  51 => '/xml/schema_intro.asp',
  52 => '/xml/xsl_intro.asp',
  53 => '/xml/xpath_intro.asp',
  54 => '/xml/xquery_intro.asp',
  55 => '/tags/default.asp',
  56 => '/tags/ref_eventattributes.asp',
  57 => '/colors/default.asp',
  58 => '/tags/ref_attributes.asp',
  59 => '/tags/ref_canvas.asp',
  60 => '/graphics/svg_reference.asp',
  61 => '/graphics/google_maps_reference.asp',
  62 => '/charsets/default.asp',
  63 => '/charsets/ref_html_ascii.asp',
  64 => '/charsets/ref_html_ansi.asp',
  65 => '/charsets/ref_html_ansi.asp',
  66 => '/charsets/ref_html_8859.asp',
  67 => '/charsets/ref_html_symbols.asp',
  68 => '/charsets/ref_html_utf8.asp',
  69 => '/cssref/default.asp',
  70 => '/cssref/css3_browsersupport.asp',
  71 => '/cssref/css_selectors.asp',
  72 => '/w3css/w3css_references.asp',
  73 => '/bootstrap/bootstrap_ref_all_classes.asp',
  74 => '/icons/icons_reference.asp',
  75 => '/xml/dom_nodetype.asp',
  76 => '/xml/dom_http.asp',
  77 => '/xml/xsl_elementref.asp',
  78 => '/xml/schema_elements_ref.asp',
  79 => '/jsref/default.asp',
  80 => '/jsref/default.asp',
  81 => '/jquery/jquery_ref_overview.asp',
  82 => '/angular/angular_ref_directives.asp',
  83 => '/w3js/w3js_references.asp',
  84 => '/php/php_ref_overview.asp',
  85 => '/sql/sql_ref_keywords.asp',
  86 => '/python/python_reference.asp',
  87 => '/asp/asp_ref_response.asp',
  88 => '/html/html_examples.asp',
  89 => '/html/html_exercises.asp',
  90 => '/css/css_examples.asp',
  91 => '/css/css_exercises.asp',
  92 => '/w3css/w3css_examples.asp',
  93 => '/w3css/w3css_templates.asp',
  94 => '/bootstrap/bootstrap_examples.asp',
  95 => '/howto/default.asp',
  96 => '/graphics/svg_examples.asp',
  97 => '/js/js_examples.asp',
  98 => '/js/js_exercises.asp',
  99 => '/js/js_dom_examples.asp',
  100 => '/jquery/jquery_examples.asp',
  101 => '/angular/angular_examples.asp',
  102 => '/js/js_ajax_examples.asp',
  103 => '/w3js/w3js_examples.asp',
  104 => '/php/php_examples.asp',
  105 => '/asp/asp_examples.asp',
  106 => '/sql/sql_exercises.asp',
  107 => '/python/python_exercises.asp',
  108 => '/xml/xml_examples.asp',
  109 => '/xml/xsl_examples.asp',
  110 => '/xml/xpath_examples.asp',
  111 => '/xml/schema_example.asp',
  112 => '/graphics/svg_examples.asp',
  113 => '/quiztest/quiztest.asp?Qtest=HTML',
  114 => '/quiztest/quiztest.asp?Qtest=CSS',
  115 => '/quiztest/quiztest.asp?Qtest=JavaScript',
  116 => '/quiztest/quiztest.asp?Qtest=Bootstrap',
  117 => '/quiztest/quiztest.asp?Qtest=jQuery',
  118 => '/quiztest/quiztest.asp?Qtest=PHP',
  119 => '/quiztest/quiztest.asp?Qtest=SQL',
  120 => '/quiztest/quiztest.asp?Qtest=XML',
  121 => 'javascript:void(0)',
  122 => 'default.asp',
  123 => 'php_intro.asp',
  124 => 'php_install.asp',
  125 => 'php_syntax.asp',
  126 => 'php_variables.asp',
  127 => 'php_echo_print.asp',
  128 => 'php_datatypes.asp',
  129 => 'php_string.asp',
  130 => 'php_constants.asp',
  131 => 'php_operators.asp',
  132 => 'php_if_else.asp',
  133 => 'php_switch.asp',
  134 => 'php_looping.asp',
  135 => 'php_looping_for.asp',
  136 => 'php_functions.asp',
  137 => 'php_arrays.asp',
  138 => 'php_arrays_sort.asp',
  139 => 'php_superglobals.asp',
  140 => 'php_forms.asp',
  141 => 'php_form_validation.asp',
  142 => 'php_form_required.asp',
  143 => 'php_form_url_email.asp',
  144 => 'php_form_complete.asp',
  145 => 'php_arrays_multi.asp',
  146 => 'php_date.asp',
  147 => 'php_includes.asp',
  148 => 'php_file.asp',
  149 => 'php_file_open.asp',
  150 => 'php_file_create.asp',
  151 => 'php_file_upload.asp',
  152 => 'php_cookies.asp',
  153 => 'php_sessions.asp',
  154 => 'php_filter.asp',
  155 => 'php_filter_advanced.asp',
  156 => 'php_error.asp',
  157 => 'php_exception.asp',
  158 => 'php_mysql_intro.asp',
  159 => 'php_mysql_connect.asp',
  160 => 'php_mysql_create.asp',
  161 => 'php_mysql_create_table.asp',
  162 => 'php_mysql_insert.asp',
  163 => 'php_mysql_insert_lastid.asp',
  164 => 'php_mysql_insert_multiple.asp',
  165 => 'php_mysql_prepared_statements.asp',
  166 => 'php_mysql_select.asp',
  167 => 'php_mysql_delete.asp',
  168 => 'php_mysql_update.asp',
  169 => 'php_mysql_select_limit.asp',
  170 => 'php_xml_parsers.asp',
  171 => 'php_xml_simplexml_read.asp',
  172 => 'php_xml_simplexml_get.asp',
  173 => 'php_xml_parser_expat.asp',
  174 => 'php_xml_dom.asp',
  175 => 'php_ajax_intro.asp',
  176 => 'php_ajax_php.asp',
  177 => 'php_ajax_database.asp',
  178 => 'php_ajax_xml.asp',
  179 => 'php_ajax_livesearch.asp',
  180 => 'php_ajax_rss_reader.asp',
  181 => 'php_ajax_poll.asp',
  182 => 'php_examples.asp',
  183 => 'php_quiz.asp',
  184 => 'php_exercises.asp',
  185 => 'php_exam.asp',
  186 => 'php_ref_overview.asp',
  187 => 'php_ref_array.asp',
  188 => 'php_ref_calendar.asp',
  189 => 'php_ref_date.asp',
  190 => 'php_ref_directory.asp',
  191 => 'php_ref_error.asp',
  192 => 'php_ref_filesystem.asp',
  193 => 'php_ref_filter.asp',
  194 => 'php_ref_ftp.asp',
  195 => 'php_ref_http.asp',
  196 => 'php_ref_libxml.asp',
  197 => 'php_ref_mail.asp',
  198 => 'php_ref_math.asp',
  199 => 'php_ref_misc.asp',
  200 => 'php_ref_mysqli.asp',
  201 => 'php_ref_simplexml.asp',
  202 => 'php_ref_string.asp',
  203 => 'php_ref_xml.asp',
  204 => 'php_ref_zip.asp',
  205 => 'php_ref_timezones.asp',
  206 => 'php_ref_http.asp',
  207 => 'php_ref_mail.asp',
  208 => 'http://www.xmlsoft.org/downloads.html',
  209 => 'func_libxml_clear_errors.asp',
  210 => 'func_libxml_get_errors.asp',
  211 => 'func_libxml_get_last_error.asp',
  212 => 'func_libxml_use_internal_errors.asp',
  213 => 'php_ref_http.asp',
  214 => 'php_ref_mail.asp',
  215 => '/colors/colors_picker.asp',
  216 => '/colors/colors_picker.asp',
  217 => '/howto/default.asp',
  218 => '/howto/howto_js_tabs.asp',
  219 => '/howto/howto_css_dropdown.asp',
  220 => '/howto/howto_js_accordion.asp',
  221 => '/howto/howto_js_sidenav.asp',
  222 => '/howto/howto_js_topnav.asp',
  223 => '/howto/howto_css_modals.asp',
  224 => '/howto/howto_js_progressbar.asp',
  225 => '/howto/howto_css_parallax.asp',
  226 => '/howto/howto_css_login_form.asp',
  227 => '/howto/howto_html_include.asp',
  228 => '/howto/howto_google_maps.asp',
  229 => '/howto/howto_js_rangeslider.asp',
  230 => '/howto/howto_css_tooltip.asp',
  231 => '/howto/howto_js_slideshow.asp',
  232 => '/howto/howto_js_filter_lists.asp',
  233 => '/howto/howto_js_sort_list.asp',
  234 => 'javascript:void(0);',
  235 => '//www.w3schools.com/cert/default.asp',
  236 => '/cert/cert_html.asp',
  237 => '/cert/cert_css.asp',
  238 => '/cert/cert_javascript.asp',
  239 => '/cert/cert_php.asp',
  240 => '/cert/cert_jquery.asp',
  241 => '/cert/cert_bootstrap.asp',
  242 => '/cert/cert_xml.asp',
  243 => '//www.w3schools.com/cert/default.asp',
  244 => 'javascript:void(0);',
  245 => 'javascript:void(0);',
  246 => '/forum/default.asp',
  247 => '/about/default.asp',
  248 => '/html/default.asp',
  249 => '/css/default.asp',
  250 => '/js/default.asp',
  251 => '/howto/default.asp',
  252 => '/w3css/default.asp',
  253 => '/bootstrap/default.asp',
  254 => '/sql/default.asp',
  255 => '/php/default.asp',
  256 => '/jquery/default.asp',
  257 => '/python/default.asp',
  258 => '/tags/default.asp',
  259 => '/cssref/default.asp',
  260 => '/jsref/default.asp',
  261 => '/w3css/w3css_references.asp',
  262 => '/bootstrap/bootstrap_ref_all_classes.asp',
  263 => '/sql/sql_ref_keywords.asp',
  264 => '/php/php_ref_overview.asp',
  265 => '/colors/colors_names.asp',
  266 => '/jquery/jquery_ref_overview.asp',
  267 => '/python/python_reference.asp',
  268 => '/html/html_examples.asp',
  269 => '/css/css_examples.asp',
  270 => '/js/js_examples.asp',
  271 => '/howto/default.asp',
  272 => '/w3css/w3css_examples.asp',
  273 => '/bootstrap/bootstrap_examples.asp',
  274 => '/php/php_examples.asp',
  275 => '/jquery/jquery_examples.asp',
  276 => '/angular/angular_examples.asp',
  277 => '/xml/xml_examples.asp',
  278 => '/cert/default.asp',
  279 => '/cert/default.asp',
  280 => '/cert/default.asp',
  281 => '/cert/default.asp',
  282 => '/cert/default.asp',
  283 => '/cert/default.asp',
  284 => '/cert/default.asp',
  285 => '/about/about_copyright.asp',
  286 => '/about/about_privacy.asp',
  287 => '/about/about_copyright.asp',
  288 => '//www.w3schools.com/w3css/',
  289 => '//www.w3schools.com',
) array (
  0 => 'https://www.bitdegree.org/',
  1 => 'https://www.bitdegree.org/',
  2 => 'https://www.bitdegree.org',
  3 => 'https://www.bitdegree.org/courses',
  4 => 'https://www.bitdegree.org/courses',
  5 => 'https://www.bitdegree.org/tag/gamified',
  6 => 'https://www.bitdegree.org/learn/',
  7 => 'https://www.bitdegree.org/tutorials/',
  8 => 'https://www.bitdegree.org/register',
  9 => 'https://www.bitdegree.org/learn/',
  10 => '#',
  11 => 'https://www.bitdegree.org/learn/html-basics/',
  12 => 'https://www.bitdegree.org/learn/css-basics/',
  13 => 'https://www.bitdegree.org/learn/learn-php/',
  14 => 'https://www.bitdegree.org/learn/javascript-basics/',
  15 => 'https://www.bitdegree.org/learn/learn-sql/',
  16 => 'https://www.bitdegree.org/learn/bootstrap-css/',
  17 => 'https://www.bitdegree.org/learn/how-does-blockchain-work/',
  18 => 'https://www.bitdegree.org/learn/jquery-tutorial/',
  19 => 'https://www.bitdegree.org/learn/how-to-install-git/',
  20 => 'https://www.bitdegree.org/learn/inspect-element/',
  21 => 'https://www.bitdegree.org/learn/html-basics/',
  22 => 'https://www.bitdegree.org/learn/css-basics/',
  23 => 'https://www.bitdegree.org/learn/learn-php/',
  24 => 'https://www.bitdegree.org/learn/javascript-basics/',
  25 => 'https://www.bitdegree.org',
  26 => 'https://www.bitdegree.org/courses',
  27 => 'https://www.bitdegree.org/courses',
  28 => 'https://www.bitdegree.org/tag/gamified',
  29 => 'https://www.bitdegree.org/learn/',
  30 => 'https://www.bitdegree.org/tutorials/',
  31 => 'https://www.bitdegree.org/register',
  32 => 'https://www.bitdegree.org',
  33 => '#sidebar-menu',
  34 => 'https://www.bitdegree.org/learn/',
  35 => 'https://www.bitdegree.org/learn/html-basics/',
  36 => 'https://www.bitdegree.org/learn/css-basics/',
  37 => 'https://www.bitdegree.org/learn/learn-php/',
  38 => 'https://www.bitdegree.org/learn/javascript-basics/',
  39 => 'https://www.bitdegree.org/learn/learn-sql/',
  40 => 'https://www.bitdegree.org/learn/bootstrap-css/',
  41 => 'https://www.bitdegree.org/learn/how-does-blockchain-work/',
  42 => 'https://www.bitdegree.org/learn/jquery-tutorial/',
  43 => 'https://www.bitdegree.org/learn/how-to-install-git/',
  44 => 'https://www.bitdegree.org/learn/inspect-element/',
  45 => 'https://www.bitdegree.org/courses/learn-solidity-space-doggos/',
  46 => 'https://www.bitdegree.org/',
  47 => '#sidebar-menu-toggle',
  48 => 'https://www.bitdegree.org/learn/learn-php/',
  49 => 'https://www.bitdegree.org/learn/what-is-php/',
  50 => 'https://www.bitdegree.org/learn/how-to-install-php/',
  51 => 'https://www.bitdegree.org/learn/php-code/',
  52 => 'https://www.bitdegree.org/learn/php-variable-scope/',
  53 => 'https://www.bitdegree.org/learn/php-class-example/',
  54 => 'https://www.bitdegree.org/learn/php-data-types/',
  55 => 'https://www.bitdegree.org/learn/php-ajax-example/',
  56 => 'https://www.bitdegree.org/learn/what-is-ajax/',
  57 => 'https://www.bitdegree.org/learn/php-ajax-search/',
  58 => 'https://www.bitdegree.org/learn/php-ajax-post/',
  59 => 'https://www.bitdegree.org/learn/ajax-polling/',
  60 => 'https://www.bitdegree.org/learn/php-rss-feed-reader/',
  61 => 'https://www.bitdegree.org/learn/php-read-xml/',
  62 => 'https://www.bitdegree.org/learn/php-array/',
  63 => 'https://www.bitdegree.org/learn/php-array-of-arrays/',
  64 => 'https://www.bitdegree.org/learn/php-sort-array-by-key/',
  65 => 'https://www.bitdegree.org/learn/php-define-constant/',
  66 => 'https://www.bitdegree.org/learn/php-isset/',
  67 => 'https://www.bitdegree.org/learn/php-date-time/',
  68 => 'https://www.bitdegree.org/learn/php-error-handling/',
  69 => 'https://www.bitdegree.org/learn/php-try-catch/',
  70 => 'https://www.bitdegree.org/learn/php-read-file/',
  71 => 'https://www.bitdegree.org/learn/php-write-to-file/',
  72 => 'https://www.bitdegree.org/learn/how-to-open-a-php-file/',
  73 => 'https://www.bitdegree.org/learn/php-file-upload/',
  74 => 'https://www.bitdegree.org/learn/php-filter-sanitize/',
  75 => 'https://www.bitdegree.org/learn/php-sanitize-input/',
  76 => 'https://www.bitdegree.org/learn/php-form-example/',
  77 => 'https://www.bitdegree.org/learn/php-required-field/',
  78 => 'https://www.bitdegree.org/learn/php-preg_match/',
  79 => 'https://www.bitdegree.org/learn/php-form-validation/',
  80 => 'https://www.bitdegree.org/learn/php-form-action/',
  81 => 'https://www.bitdegree.org/learn/php-function/',
  82 => 'https://www.bitdegree.org/learn/php-if-else/',
  83 => 'https://www.bitdegree.org/learn/php-include-file/',
  84 => 'https://www.bitdegree.org/learn/php-while-loop/',
  85 => 'https://www.bitdegree.org/learn/php-foreach-loop/',
  86 => 'https://www.bitdegree.org/learn/php-mysql-connect/',
  87 => 'https://www.bitdegree.org/learn/mysql-create-database/',
  88 => 'https://www.bitdegree.org/learn/mysql-create-table-example/',
  89 => 'https://www.bitdegree.org/learn/mysql-delete-row/',
  90 => 'https://www.bitdegree.org/learn/mysql-insert-into/',
  91 => 'https://www.bitdegree.org/learn/mysql-last-insert-id/',
  92 => 'https://www.bitdegree.org/learn/mysql-insert-multiple-rows/',
  93 => 'https://www.bitdegree.org/learn/php-mysql-database/',
  94 => 'https://www.bitdegree.org/learn/php-pdo/',
  95 => 'https://www.bitdegree.org/learn/mysql-select-database/',
  96 => 'https://www.bitdegree.org/learn/mysql-limit-offset/',
  97 => 'https://www.bitdegree.org/learn/mysql-update-syntax/',
  98 => 'https://www.bitdegree.org/learn/php-or-operator/',
  99 => 'https://www.bitdegree.org/learn/php-calendar-code/',
  100 => 'https://www.bitdegree.org/learn/php-date-format/',
  101 => 'https://www.bitdegree.org/learn/php-directory/',
  102 => 'https://www.bitdegree.org/learn/php-error-handler/',
  103 => 'https://www.bitdegree.org/learn/php-file-function/',
  104 => 'https://www.bitdegree.org/learn/php-filter/',
  105 => 'https://www.bitdegree.org/learn/php-create-directory/',
  106 => 'https://www.bitdegree.org/learn/php-http-response/',
  107 => 'https://www.bitdegree.org/learn/php-libxml/',
  108 => 'https://www.bitdegree.org/learn/php-mail-function/',
  109 => 'https://www.bitdegree.org/learn/php-math-functions/',
  110 => 'https://www.bitdegree.org/learn/__trashed-7/',
  111 => 'https://www.bitdegree.org/learn/php-mysqli/',
  112 => 'https://www.bitdegree.org/learn/php-simplexml/',
  113 => 'https://www.bitdegree.org/learn/php-string-replace/',
  114 => 'https://www.bitdegree.org/learn/xml-parsing/',
  115 => 'https://www.bitdegree.org/learn/php-zip-files/',
  116 => 'https://www.bitdegree.org/learn/php-sessions/',
  117 => 'https://www.bitdegree.org/learn/php-string-length/',
  118 => 'https://www.bitdegree.org/learn/php-global-variable/',
  119 => 'https://www.bitdegree.org/learn/php-switch-case/',
  120 => 'https://www.bitdegree.org/learn/xml-parser/',
  121 => 'https://www.bitdegree.org/learn/expat-xml-parser/',
  122 => 'https://www.bitdegree.org/learn/php-xml-parser/',
  123 => 'https://www.bitdegree.org/learn/php-xml/',
  124 => 'https://www.bitdegree.org/learn/php-parse-xml/',
  125 => 'https://www.bitdegree.org/learn/php-array-functions/',
  126 => 'https://www.bitdegree.org/learn/php-date-function/',
  127 => 'https://www.bitdegree.org/learn/php-mail/',
  128 => 'https://www.bitdegree.org/learn/php-explode-function/',
  129 => 'https://www.bitdegree.org/learn/php-substr-function/',
  130 => 'https://www.bitdegree.org/learn/php-str_replace/',
  131 => 'https://www.bitdegree.org/learn/php-json_decode/',
  132 => 'https://www.bitdegree.org/learn/php-array-push/',
  133 => 'https://www.bitdegree.org/learn/php-array-length/',
  134 => '#sidebar-menu-toggle',
  135 => 'https://www.bitdegree.org/learn/category/php-cheat-sheet/',
  136 => '#PHP_5_libxml_Functions_Main_Tips',
  137 => '#PHP_libxml_Functions',
  138 => '#PHP_5_libxml_Prefefined_Constants',
  139 => 'http://xmlsoft.org',
  140 => 'https://www.bitdegree.org/register',
  141 => 'https://www.bitdegree.org/courses',
  142 => 'https://www.bitdegree.org/tag/gamified',
  143 => 'https://www.bitdegree.org/learn/',
  144 => 'https://www.bitdegree.org/tutorials/',
  145 => 'https://www.bitdegree.org/hiring',
  146 => 'https://www.bitdegree.org/bitdegree-vision.pdf',
  147 => 'https://blog.bitdegree.org/',
  148 => 'https://www.bitdegree.org/partners',
  149 => 'https://www.bitdegree.org/policies',
  150 => 'https://www.bitdegree.org/privacy-policy',
  151 => 'https://www.bitdegree.org/cookie-policy',
  152 => 'https://www.bitdegree.org/terms-of-service',
  153 => 'https://www.bitdegree.org/learn/best-code-editor/',
  154 => 'https://www.bitdegree.org',
  155 => 'https://www.bitdegree.org/learn/php-mail-function/',
  156 => '#',
  157 => 'https://www.bitdegree.org/cookie-policy',
)

0 个答案:

没有答案