PHP Count the lenght of each value in a array/string (tags)
Posted
by
2by
on Stack Overflow
See other posts from Stack Overflow
or by 2by
Published on 2012-04-15T23:22:29Z
Indexed on
2012/04/15
23:29 UTC
Read the original article
Hit count: 185
Users writing an article have the option to write some tags, tags are written like this:
tag1, tag2, tag3
So tags are stored like: $tags = "tag1, tag2, tag3";
I want to make sure, every tag has a minimum of 3 characters, so i need to validate the tags.
I have tried this:
$tagsstring = explode(",", $tags);
$tagslength = array_map('strlen', $tagsstring);
if (min($tagslength) < 3) {
echo "Error... Each tag has to be at least 3 characters.";
}
It seems to work, sometimes... But of you write:
tag1, df
It wont give an error.
Any suggestions?
© Stack Overflow or respective owner