tags:

views:

79

answers:

1

Is there a way if I count the number of tags inside the for loop for example.

if($tags == 0){
    echo 'no tags entered.';
} else if($tags == 1){
    echo $tags . 'tag entered';
} else {
    echo $tags . 'tags entered';
}

Here is my code.

for ($x = 0; $x < count($tags); $x++){

    if ($tags[$x] != '') {// get rid of empty tags
        echo ' ' . strtolower(strip_tags($tags[$x])) . ',';
    }//end of get rid of empty tags

}
+2  A: 

Rude comment aside, I believe this is what you are trying to do:

// gets rid of empty tags, 
// trims them and sets them to lowercase
for ($i=0; $i<count($tags); $i++) {
    if (trim($tags[$i]) != '') { // using trim to get rid of spaces
        $tags[$i] = strtolower(strip_tags($tags[$i]));
    } else {  
        unset($tags[$i]); // gets rid of empty tags
    }
}

// print out tags
switch (count($tags)) {
    case 0:
        echo 'no tags entered.';
        break;
    case 1:
        echo $tags[0] . ' tag entered.';
        break;
    default:
        echo implode(', ', $tags) . ' tags entered';
        break;
}

Next time, learn to:

  • Be more respectful
  • Word your question properly, and give examples of expected input and output when necessary

In that order.

quantumSoup
next time a softer tone would do, but thanks for the help
Dis9