简体   繁体   English

如何使用php和mysql逐行分隔单词

[英]How to separate words from a row individually using php and mysql

I have a mysql database with a table called keywords -- see below 我有一个带有名为关键字的表的mysql数据库-参见下文 在此处输入图片说明

**** As you can see the row has more than one word listed inside. ****如您所见,该行内部列出了多个单词。

MY QUESTION Is there a way to separate each word on it's own using mysql and php. 我的问题是否存在使用mysql和php单独分隔每个单词的方法。 Right now it combines all the words as one instead of individually. 现在,它将所有单词组合为一个单词,而不是单个单词。

The picture below is showing you words but one button may contain 3 or more words. 下图为您显示单词,但一个按钮可能包含3个或更多单词。 在此处输入图片说明 I need for the words to be unique and on their own. 我需要使这些单词具有独特性并靠它们自己。 Can this be done in MYSQL? 可以在MYSQL中完成吗? If so can you please provide the php coding, thank you. 如果可以,请提供php编码,谢谢。

you can separate the keyword by comma and space using PHP. 您可以使用PHP以逗号和空格分隔关键字。

//Split the keyword into array
$keywords_array = explode(", ", $keywords);

//Use array_unique to remove duplicates
$unique_keywords_array = array_unique($keywords_array);

//Print output
foreach($unique_keywords_array as $key) {
    echo $key . "<br />";
}

As you didn't share any code, i can give you a simple guess so you can proceed further :- 因为您没有共享任何代码,所以我可以给您一个简单的猜测,以便您可以进一步进行:-

Get data from your table with php and use explode function to separate each word. 用php从表中获取数据,并使用explode函数分隔每个单词。

最好的选择是使用explode函数,下面的链接是php网站中explode的参考: http : //php.net/manual/en/function.explode.php

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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