验证URL有两种一种是利用正则表达式来验证URL是不是合适url规则了,另一个是利用函数来访问指定url看看是否可正常访问了,如果能正常访问自然就是合法的url地址了。
例子1
<?php function isValidUrl($url) { $patern = '/^http[s]?:\/\/'. '(([0-9]{1,3}\.){3}[0-9]{1,3}'. // IP形式的URL- 199.194.52.184 '|'. // 允许IP和DOMAIN(域名) '([0-9a-z_!~*\'()-]+\.)*'. // 三级域验证- www. '([0-9a-z][0-9a-z-]{0,61})?[0-9a-z]\.'. // 二级域验证 '[a-z]{2,6})'. // 顶级域验证.com or .museum '(:[0-9]{1,4})?'. // 端口- :80 '((\/\?)|'. // 如果含有文件对文件部分进行校验 '(\/[0-9a-zA-Z_!~\*\'\(\)\.;\?:@&=\+\$,%#-\/]*)?)$/'; if(!preg_match($patern, $url)) { die( '您输入的URL格式有问题,请检查!'); } }
例子2
上面的例子只是验证url是不是正常的不代表是否可以访问了,我们可以使用如curl函数进行方法
$url = "http://www.phprm.com "; $curl = curl_init($url); curl_setopt($curl, CURLOPT_NOBODY, true); $result = curl_exec($curl); if ($result !== false) { $statusCode = curl_getinfo($curl, CURLINFO_HTTP_CODE); if ($statusCode == 404) { echo "URL Not Exists" } else { echo "URL Exists"; } } else { echo "URL not Exists"; }
除了这个函数还可以使用php的很多函数如 file、file_get_contents()、fopen函数来进行检测了。

如何解决PHPWarning:fopen():failedtoopenstream:Nosuchfileordirectory在使用PHP开发过程中,我们经常会遇到一些文件操作的问题,其中之一就是"PHPWarning:fopen():failedtoopenstream:Nosuchfileordirectory

如何解决PHPWarning:fopen():SSLoperationfailedinfile.phponlineX在PHP编程中,我们经常使用fopen函数来打开文件或者URL,并进行相关操作。然而,在使用fopen函数时,有时候会遇到类似于Warning:fopen():SSLoperationfailedinfile.p

如何解决PHPWarning:fopen():failedtoopenstream:Permissiondenied在开发PHP程序的过程中,我们常常会遇到一些报错信息,比如PHPWarning:fopen():failedtoopenstream:Permissiondenied。这个错误通常是由于文件或目录权限不正

在Matlab中,fopen函数用于打开文件并返回文件标识符,以便后续对文件进行读取或写入操作。根据需要选择适当的权限选项来打开文件,并在操作完成后及时关闭文件。需要注意的是,打开文件后需要确保在不再需要文件时及时关闭文件,以释放系统资源。另外,如果文件打开失败或操作出错,可以通过错误处理机制进行相应的处理。

在PHP开发中,对文件的操作是非常常见的。一般情况下,我们需要进行文件的读取、写入、删除等操作。其中,文件的读取可以使用fopen函数和fread函数,文件的写入可以使用fopen函数、fwrite函数和fclose函数。本文将介绍php如何使用fopen、fwrite和fclose进行文件操作。一、fopen函数fopen函数用于打开文件,它的语法如下:r

C中的fopen()方法用于打开指定的文件。我们举个例子来理解一下问题语法FILE*fopen(filename,mode)以下是使用fopen()打开文件的有效模式:‘r’、‘w’、‘a’、‘r+’、‘w+’、‘a+’。详细信息请访问C库函数-fopen()

如何解决PHPWarning:fopen():failedtoopenstream:Nosuchfileordirectoryinfile.phponlineX在开发和运行PHP程序时,我们有时会遇到PHPWarning:fopen():failedtoopenstream:Nosuchfileor

PHP的preg_match()函数:如何使用正则表达式匹配字符串,需要具体代码示例正则表达式在字符串处理中是非常强大和灵活的工具。在PHP中,使用preg_match()函数可以方便地进行字符串的正则匹配,从而实现各种复杂的模式匹配和替换操作。本文将介绍preg_match()函数的用法,并提供具体的代码示例来帮助读者更好地理解和应用。preg_match


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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Atom editor mac version download
The most popular open source editor

Dreamweaver Mac version
Visual web development tools

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

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.
