URL (Uniform Resoure Locator: Uniform Resource Locator) is the address of the WWW page. It is grouped from left to right by the following parts:
·Internet resource type (scheme ): Indicates the tools used by WWW client programs to operate. For example, "http://" represents the WWW server, "ftp://" represents the FTP server, "gopher://" represents the Gopher server, and "new:" represents the Newgroup news group.
·Server address (host): Indicates the server domain name where the WWW page is located.
·Port: Sometimes (not always), for access to certain resources, the corresponding server port number needs to be given.
·Path: Indicates the location of a resource on the server (its format is the same as that in the DOS system, usually consisting of a directory/subdirectory/file name structure). As with ports, paths are not always required.
The URL address format is arranged as: scheme://host:port/path. For example, http://www.sohu.com/do
main/HXWZ is a typical URL address.
regular expressions to verify the URL. The code is as follows:
<?php $url = 'http://www.baidu.com/zongzi/oo.html'; $n = preg_match_all("/http:[\/]{2}[a-z]+[.]{1}[a-z\d\-]+[.]{1}[a-z\d]*[\/]*[A-Za-z\d]*[\/]*[A-Za-z\d]*[.]*html/",$url,$array); var_dump($array); ?>
The above is the detailed content of php uses regular expressions to verify URL example code. For more information, please follow other related articles on the PHP Chinese website!