简体   繁体   中英

how to split a string field sentence in mysql to words

I am using a CMS for adding a new product. Along with adding the product I am giving an option to add keywords.

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

Then it is inserted in to mysql table. But i want to use these keywords for a search option. Now it is saving as a string of sentences seperated by comma or space. How can I get each word back from the table?

您可以在此处此处找到处理字符串拆分的函数

You can use the PHP method: explode($delimiter, $string).

Example:

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

or

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

by using

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

or

 explode($delimiter,$string)

or

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

or

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

or

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM