root/trunk/lib/Tag.class.php

Revision 31, 0.8 kB (checked in by fabien, 3 years ago)

day 13 modifications

  • Property svn:mime-type set to text/x-php
  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
Line 
1 <?php
2  
3 class Tag
4 {
5   public static function normalize($tag)
6   {
7     $n_tag = strtolower($tag);
8
9     // remove all unwanted chars
10     $n_tag = preg_replace('/[^a-zA-Z0-9]/', '', $n_tag);
11
12     return trim($n_tag);
13   }
14
15   public static function splitPhrase($phrase)
16   {
17     $tags = array();
18     $phrase = trim($phrase);
19
20     $words = preg_split('/(")/', $phrase, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);
21     $delim = 0;
22     foreach ($words as $key => $word)
23     {
24       if ($word == '"')
25       {
26         $delim++;
27         continue;
28       }
29       if (($delim % 2 == 1) && $words[$key - 1] == '"')
30       {
31         $tags[] = trim($word);
32       }
33       else
34       {
35         $tags = array_merge($tags, preg_split('/\s+/', trim($word), -1, PREG_SPLIT_NO_EMPTY));
36       }
37     }
38
39     return $tags;
40   }
41 }
42
43 ?>
Note: See TracBrowser for help on using the browser.