开发者

How to separate values in the same input

开发者 https://www.devze.com 2023-02-08 19:10 出处:网络
Hey guys, I have two questions. First, how do I separate values in the same input area that are separated with a comma when I\'m using php. How can I differentiate them? And second, 开发者_运维知识库h

Hey guys, I have two questions. First, how do I separate values in the same input area that are separated with a comma when I'm using php. How can I differentiate them? And second, 开发者_运维知识库how can I separate values that use jquery's autosuggest in php?

Thanks in advance.


For first question:

$values = explode(',', $_POST['values']);

$values will be an indexed array.


Assuming this text input:

<input type="text" name="choices">

You would explode the value "one,two,three" using:

$choices = explode(',', $_GET['choices']); // or $_POST, depending

Which leaves you with $choices == array( 'one', 'two', 'three' ). Also note that PHP understands a special notation for form fields that return as part of an array:

<input type="text" name="choices[]" value="one">
<input type="text" name="choices[]" value="two">
<input type="text" name="choices[]" value="three">

This will automatically parse into an array:

$choices = $_GET['choices']; // array( 'one', 'two', three' )

The second part of your question could use clarification.

0

精彩评论

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

关注公众号