开发者

User input categories

开发者 https://www.devze.com 2023-03-30 20:10 出处:网络
(PHP, MySQL, 开发者_如何学JAVAHTML) I want users at my site to be able to submit text. I also want them to type in their own categories for this text. I currently have a textarea, with a maxlenght of

(PHP, MySQL, 开发者_如何学JAVAHTML)

I want users at my site to be able to submit text. I also want them to type in their own categories for this text. I currently have a textarea, with a maxlenght of 100, where they can submit categories for their text. Although I don't want several possible categories put in going in to my database in a block, but one and one. Is there any good way to seperate the user's inputs and pick out word for word, and put each category in to the database by itself?


You would need to ask your users to put in their words (I'm assuming these are like tags on SO) separated by spaces, or commas if you want multi-word categories.

example: dogs, the whole zoo, cats, sheep, farm animals

When you receive them in PHP, explode() on the delimiter you chose and input them as separate rows into the database.

// example - comma separated...
$categories = explode(",", $inputwords);
foreach ($categories as $cat) {
   // insert it into the database.
}


PHP function explode should do the trick, juste tell them to separate categories using spaces for example.

0

精彩评论

暂无评论...
验证码 换一张
取 消