The Script:
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" >
<input type="text" name="hashtag1" />
<input type="text" name="hashtag2" />
<input type="text" name="hashtag3" />
<input type="text" name="hashtag4" />
<input type="submit" name="submit" />
</form>
<?php
if(isset($_POST['submit'])){
if(isset($_POST['hashtag1'])) {
$hashtag1 = $_POST['hashtag1'];
}
if(isset($_POST['hashtag2'])){
$hashtag2 = $_POST['hashtag2'];
}
if(isset($_POST['hashtag3'])){
$hashtag3 = $_POST['hashtag3'];
}
if(isset($_POST['hashtag4'])){
$hashtag4 = $_POST['hashtag4'];
}
$myarray = array($hashtag1, $hashtag2, $hashtag3, $hashtag4);
for($i = 0; $i < count($myarray); $i++){
if(!preg_match('/^(?=.{2,140}$)(#|\x{ff03}){1}([0-9_\p{L}]*[_\p{L}][0-9_\p{L}]*)$/u', $myarray[$i])){
echo "Please check your hashtags!";
exit;
}
}
function array_has_dupes($array) {
return count($array) !== count(array_unique($array));
}
if(array_has_dupes($myarray) == true){
echo "Please make sure you do not have duplicate hashtags!";
exit;
}
echo "Hello World!";
}
?>
When I leave one input field of those four input fields empty, then I get "Please check your hashtags." printed on screen.
My question is, how to modify the script so leaving one or more input fields empty is allowed?
I am using the "PHP Twitter Hashtag Validation Regex" from GitHub: link