i have one html page in them one text-box
<input type="text" id="region&activity">
<input type="button" id="result" value="submit">
in text-box i am entered Race in Gujarat
i want to store this value in to Array
something. Race
in one array and Gujarat
in another array
help me or give some idea to do this.
thanks
try this
<?php
$abc='race in gujrat';
list($event,$state) = split('in',$abc);
echo $event;
echo $state;
?>
and store that string in array
Using PHP
This result assumes you are splitting them into an array after the space.
$text = "Race in Gujarat";
$result = explode(" ", $text);
echo $result[0]; //Race
echo $result[1]; //in
echo $result[2]; //Gujarat
As your question isn't clearly defined, I'm assuming that you wish to remove the word "in", and split the the string into separate arrays on the space character.
How about (using jQuery for convenience):
var splitRegion=$("#region&activity").val().replace(/in /g," ").split(" ");
myArray1.push(splitRegion[0]);
myArray2.push(splitRegion[1]);
By the way, I believe an ampersand (&) is an illegal character in an id.
if you want to use java script then do something this type:-
<script>
$(function(){
$("#filter").click(function(){
var name = $('#select').val();
alert(name);
$.ajax({
type: "POST",
data: {"name":name} ,
url: "array.php",
async: false,
success: function(result) {
alert(result);
$("#result").text(result);
}
});
});
});
</script>
this is your html code:-
</head>
<body>
<input type="text" id="select">
<input type="button" id="filter" name="button" value="Search">
<div id="result">
</div>
</body>
</html>
this is array.php:-
<?php
$name= $_POST['name'];
$result = explode("in", $name);
foreach($result as $row){
echo $row;
}
?>
try this:-
<?php
$abc= $_POST['name'];
list($event,$state) = explode('in',$abc);
$array1[]=$event;
$array2[]=$state;
foreach($array1 as $city)
{
echo $city;
}
foreach($array2 as $st)
{
echo $st;
}
?>
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.