在PHP的官网上看到的parse_url()函数的替代方案。结果和parse_url()函数差不多,是使用正则实现的。URI 是 Web上可用的每种资源
- HTML文档、图像、视频片段、程序等 - 由一个通用资源标志符(Uniform Resource Identifier, 简称"URI")进行定位。
对象分组:
^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))? 12 3 4
测试代码如下:
<?php $search = '~^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?~i'; $url = 'http://www.jb51.net/pub/ietf/uri/#Gonn'; $url = trim($url); preg_match_all($search, $url ,$rr); printf("<p>输出URL数据为:</p><pre class="brush:php;toolbar:false">%s\n",var_export( $rr ,TRUE)); /* 各分组如下 $1 = http: $2 = http $3 = //www.nowamagic.net $4 = www.nowamagic.net $5 = /pub/ietf/uri/ $6 =
上面的正则表达式可以获取URL中的任何一部分,下面的代码则简单一些:
<?php // 从 URL 中取得主机名 preg_match("/^(http:\/\/)?([^\/]+)/i", "http://www.jb51.net/index.html", $matches); $host = $matches[2]; // 从主机名中取得后面两段 preg_match("/[^\.\/]+\.[^\.\/]+$/", $host, $matches); echo "domain name is: {$matches[0]}\n"; ?>

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

SublimeText3 Chinese version
Chinese version, very easy to use

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.
