2012-06-13 40 views
0

我正在使用CMS添加新產品。除了添加產品外,我還提供了添加關鍵字的選項。如何在mysql中將字符串字段句拆分爲單詞

Keywords:<textarea rows="10" cols="20" name="keywords"></textarea> 

然後它被插入到mysql表中。但我想使用這些關鍵字作爲搜索選項。現在它被保存爲一串由逗號或空格分隔的句子。我怎樣才能從桌子上找回每一個字?

+0

http://stackoverflow.com/questions/6152137/mysql-string-split – Rishabh

+0

WHERE關鍵字LIKE「% %'? http://stackoverflow.com/questions/2749744/how-to-search-mulitple-value-seperated-by-commas-in-mysql – verisimilitude

回答

0

您可以使用PHP方法:爆炸($分界,$字符串)。

實施例:

$newArray = explode(' ', $yourPhraseWithSpaces); 

$newArray = explode(',', $yourPhraseWithCommas); 
0

通過使用

array preg_split (string $pattern , string $subject [, int $limit = -1 [, int $flags = 0 ]]) 

explode($delimiter,$string) 

spliti (string $pattern , string $string [, int $limit = -1 ]) 

chunk_split (string $body [, int $chunklen = 76 [, string $end = "\r\n" ]]) 

str_split (string $string [, int $split_length = 1 ])