Cara Membersihkan Input Tags

Saat develop website yang menggunakan tagging, lalu kena kasus seperti ini?

User input: baju, , sarung, celana, kaos
Hasil yang diharapkan: baju, sarung, celana, kaos

Lalu bingung membersihkan data tag yang kosong itu?

Solusinya gampang kok, nih, pakai saja potongan snippet berikut:

	$txt_tags = "baju, , sarung, celana, kaos";

	$tmp_tags = array_map('trim', explode(',', $txt_tags));
	$valid_tags = array();
	foreach($tmp_tags as $tag)
			$valid_tags[] = $tag;
	$txt_tags = implode(', ', $valid_tags);//akan menghasilkan:  baju, sarung, celana, kaos

Gimana? simpel kan?

Author: Arief Bayu Purwanto

Hello, my name is Arief Bayu Purwanto, a 24 years old father of a beautiful daughter. Interested in online programming, linux, games, and reading. Currently working on as junior developer. I live in a relatively quite and cool place called Malang. I'm available for some freelance stuff as well as some consulting job. You can see my portofolio for some previous task I've finished and some other information related to my capability. Btw, I'm plurking here.