php需要至少3个单词的表单验证

I have this php code for form validation :

if(($_FILES['file']['error'] != 0) || $title == '' || $tags == '') {
                wp_redirect(home_url('/') . '?posterror=1');
                exit; 
            }   

This form redirect you to a page error if you didn't upload a file, put a title or a tag. From this code I want to change this: $tags == '' to something like this: $tags != 3 but it doesn't work, to require minimum 3 words = 3 tags.

You need to count the words, if they are separated by spaces, use

if(($_FILES['file']['error'] != 0) || $title == '' || str_word_count($tags) < 3) {
    wp_redirect(home_url('/') . '?posterror=1');
    exit; 
}  

if they are separated by comma-space ,, use this

if(($_FILES['file']['error'] != 0) || $title == '' || count(explode(", ", $tags)) < 3) {
    wp_redirect(home_url('/') . '?posterror=1');
    exit; 
}