简体   繁体   English

将文本框值存储在数组中

[英]store the text-box value in arrays

i have one html page in them one text-box 我在其中有一个html页面一个文本框

<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 在文本框中,我进入Race in Gujarat我想将此值存储到数组中
something. 的东西。 Race in one array and Gujarat in another array 参加一个RaceGujarat参加另一个Race
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 使用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. 由于您的问题尚未明确定义,我假设您希望删除单词“ in”,并将字符串拆分为空格字符上的单独数组。

How about (using jQuery for convenience): 怎么样(为方便起见使用jQuery):

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. 顺便说一句,我相信&符是ID中的非法字符。

if you want to use java script then do something this type:- 如果您想使用Java脚本,请执行以下类型的操作:-

<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:- 这是您的html代码:-

</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:- 这是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;
}
 ?>

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

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