rernanded
Erfahrenes Mitglied
Suche ein Script mit dem ich URLs validieren kann.
Folgende Lösungen hab ich, doch irgendwie klappt keine so richtig.
Die korrekten Eingaben einer URL dürfen so aussehen. Alles andere soll abgelehnt werden.
http://subdomain.domainname.tldhttps://subdomain.domainname.tldhttp://subdomain.domainname.tld/https://subdomain.domainname.tld/http://domainname.tldhttps://domainname.tldhttp://domainname.tld/https://domainname.tld/
MONI
Folgende Lösungen hab ich, doch irgendwie klappt keine so richtig.
Die korrekten Eingaben einer URL dürfen so aussehen. Alles andere soll abgelehnt werden.
http://subdomain.domainname.tldhttps://subdomain.domainname.tldhttp://subdomain.domainname.tld/https://subdomain.domainname.tld/http://domainname.tldhttps://domainname.tldhttp://domainname.tld/https://domainname.tld/
PHP:
<!DOCTYPE html>
<html>
<body>
<form action="url_validation.php" method="post">
<input type="text" name="url1" size="100">
<input type="submit" value="check">
</form>
<form action="url_validation.php" method="post">
<input type="text" name="url2" size="100">
<input type="submit" value="check">
</form>
<form action="url_validation.php" method="post">
<input type="text" name="url3" size="100">
<input type="submit" value="check">
</form>
<?php
//$url1 = trim($_POST["url1"]);
$url1 = $_POST["url1"];
if (filter_var($url1, FILTER_VALIDATE_URL)) {
echo("$url1 is a valid URL");
} else {
echo("$url1 is not a valid URL");
}
?>
<br /><br /><br />
<?php
//$url2 = trim($_POST["url2"]);
$url2 = $_POST["url2"];
if (filter_var($url2, FILTER_VALIDATE_URL, FILTER_FLAG_HOST_REQUIRED)) {
echo("$url2 is a valid URL");
} else {
echo("$url2 is not a valid URL");
}
?>
<br /><br /><br />
<?php
//$url3 = trim($_POST["url3"]);
$url3 = $_POST["url3"];
// Removes all illegal characters from an url.
$url3 = filter_var($url3, FILTER_SANITIZE_URL);
if (filter_var($url3, FILTER_VALIDATE_URL)) {
echo("$url3 is a valid URL");
} else {
echo("$url3 is not a valid URL");
}
?>
</body>
</html>
MONI