【发布时间】:2018-12-16 01:30:21
【问题描述】:
我想要一个系统,其中从我的输入字段提交的数据必须是一个 URL,并且在 PHP 中以“http://”或“https://”开头。但是当我提交表单时,它一直提示“无效链接”,可以修复吗?
<?php
if(isset($_POST['Title'])){
$Title=$_POST['Title'];
}if(isset($_POST['Description'])){
$Description=$_POST['Description'];
}if(isset($_POST['Link'])){
$Link=$_POST['Link'];
}
if(strlen($Title) <= 5){
echo "<script> alert('Title should be more than 5 characters!')</script>";
exit;
}
if(strlen($Description) <= 5){
echo "<script> alert('Description should be more than 5 characters!')</script>";
exit;
}
$contains = "https://drive.google.com/";
if(strlen($Link) <= 5 || !preg_match("/\b($contains)\b/", $Link)){
echo "<script> alert('INVALID LINK!') </script>";
exit;
}
else{
echo "<script> alert('DONE!') </script>";
}
?>
感谢您的宝贵时间。
【问题讨论】:
-
你不想检查链接是否包含“drive.google.com”或者你只想检查这是否是有效的链接?
-
不正确@Smartpal
-
@Rainmx93 应该以drive.google.com开头
-
那么你可以使用 substr($Link, 0, strlen($contains)) 函数来检查字符串是否以drive.google.com开头