我正在使用CMS添加新產品。除了添加產品外,我還提供了添加關鍵字的選項。如何在mysql中將字符串字段句拆分爲單詞
Keywords:<textarea rows="10" cols="20" name="keywords"></textarea>
然後它被插入到mysql表中。但我想使用這些關鍵字作爲搜索選項。現在它被保存爲一串由逗號或空格分隔的句子。我怎樣才能從桌子上找回每一個字?
我正在使用CMS添加新產品。除了添加產品外,我還提供了添加關鍵字的選項。如何在mysql中將字符串字段句拆分爲單詞
Keywords:<textarea rows="10" cols="20" name="keywords"></textarea>
然後它被插入到mysql表中。但我想使用這些關鍵字作爲搜索選項。現在它被保存爲一串由逗號或空格分隔的句子。我怎樣才能從桌子上找回每一個字?
您可以使用PHP方法:爆炸($分界,$字符串)。
實施例:
$newArray = explode(' ', $yourPhraseWithSpaces);
或
$newArray = explode(',', $yourPhraseWithCommas);
通過使用
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 ])
http://stackoverflow.com/questions/6152137/mysql-string-split – Rishabh
WHERE關鍵字LIKE「% %'? http://stackoverflow.com/questions/2749744/how-to-search-mulitple-value-seperated-by-commas-in-mysql –
verisimilitude