How to take multiple values in an input type text (text box) separated by a comma in PHP, explode function, implode function
How to take multiple values in an input type text (text box) separated by a comma in PHP, explode function, implode function
In this tutorial, we will learn about the followings;
- Explode function in PHP
- Implode() Function in PHP
- How to take multiple values in an input type text (text box) separated by a comma in PHP
Explode function in PHP
The explode function is used to split a string into pieces by a specified string i.e. it breaks a string into an array.
The explode function in PHP is used to break a string into smaller text with each break occurring at the similar symbol, commonly called delimiter.
Here in the code below, we are separating the multiple values of the textbox with a comma.
Implode() Function in PHP
The implode function is a function to join the elements of an array with a specific string.
The implode() function joins the strings by taking an array of strings and using a delimiter.
Program of multiple values in an input type text (text box) separated by a comma by using explode function
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | <html> <body> <form method="post"> <table border="5" height="200" width="800" > <tr><td colspan="2"> <center> show multiple values </center> </td></tr> <tr><td>Enter values separated by comma</td> <td><input type="text" name="n" placeholder="1,2,3,4,5" /></td></tr> <tr><td>result</td> <?php if (empty($result)) $result=' result comes here' ; if(isset($_POST['save'])) { $result=0; $n1=$_POST['n']; echo "</br>"; echo "values separated by comma's are : ".$n1; echo "</br>"; $n1arr=explode(',', $n1); echo "________________________"; echo "</br>"; echo "value after spliting comma separated values by variable in array is given below </br>"; for ($i=0; $i <count($n1arr) ; $i++) { echo "$n1arr[$i]". " | "; } echo "</br>"; echo "________________________"; echo "</br>"; } ?> <td><output><?php echo $result ?></output></td></tr> <tr><td colspan="2" width="500" align="center"><input type="submit" name="save" value="calculate"></td></tr> </body> </html> |