From 8cf2d8d62c97056149c0a40e38dfcd3dbeee36c3 Mon Sep 17 00:00:00 2001 From: Gabriel Dunne Date: Fri, 23 Dec 2011 11:21:25 -0800 Subject: [PATCH] cleaned tag input style --- data.php | 22 +++++++++++++++++----- get.php | 5 +---- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/data.php b/data.php index 6dad985..0425bc4 100644 --- a/data.php +++ b/data.php @@ -41,11 +41,23 @@ function get_users(&$dbh, $args) function tag_string_to_array($tagstr) { # if has commas, split on commas # else split on spaces - // TODO - # check for quotes (for "multiple words") - $tags = array_filter(strpos($tagstr, ',') ? explode(',', $tagstr) : explode(' ', $tagstr)); + $tags = array(); + if (strpos($tagstr, ',')) { + $tags = explode(',', $tagstr); + } else { + # match all quoted strings + preg_match_all('/"(.*?)"/', $tagstr, $quoted_tags); + # strip quoted strings from tag string + $tagstr_noquotes = str_replace($quoted_tags[0], '', $tagstr); + # split new string on spaces + $tags_woutquotes = explode(' ', $tagstr_noquotes); + # merge arrays + $tags = array_merge($tags_woutquotes, $quoted_tags[1]); + } + # trim all values array_walk($tags, function(&$item, $key) { $item = trim($item); - }); - return $tags; + }); + + return array_filter($tags); } diff --git a/get.php b/get.php index 83fc234..0cbcdcc 100644 --- a/get.php +++ b/get.php @@ -121,10 +121,7 @@ function deleteClump( id, elem ) { $hasDescription = $row['description'] || false; # process tags - if ($row['tags'] == '') - $row['tags'] = array(); - else - $row['tags'] = tag_string_to_array( $row['tags'] ); + $row['tags'] = tag_string_to_array( $row['tags'] ); ?> -- 2.34.1