如何只获取IP地址/子网 [英] How to get only the IP address / subnet
问题描述
我正在使用jquery插件,它会对我的字段进行屏蔽,并且只允许用户键入正确的值。它工作得很好,但现在当我提交表单时,对象IP是一个数组,我只需要检索IP号(10.1.25.2/30)
I'm using a jquery plugin, it maskered my field and allow the user only to type the correct values. It is working very well, but now when I submit my form, the object IP is an Array, I need to retrieve only the IP number (10.1.25.2/30)
结果:
$ip = $_POST['ipaddress'];
print_r($ip);
//It returns to me
Array ( [abcd] => Array ( [0] => 10.1.25.2/30 ) )
我需要内爆数组或以这种方式做某事......请帮忙。
I need implode the Array or do something on this way.. help please.!
整个代码:
HTML页面 jQuery插件包括:
<script src="scripts/jquery.min.js" type="text/javascript">
<script src="jquery.validate/jquery.caret.js" type="text/javascript"></script>
<script src="jquery.validate/jquery.ipaddress.js" type="text/javascript"></script>
<script>
$(function(){
$('#ip').ipaddress({cidr:true});
});
</script>
<form name="form1" method="post" action="equipAction.php">
<tr>
<td>IP</td>
<td><input name="ipaddress[abcd][]" id="ip" type="text" value="<?=$ip;?>" />
<b>»» IP atribuído ao contrato do Cliente/Torre </b> </td>
</tr>
<input type='submit' name="alt" value="Edit" class="btn" />
</form>
现在我的动作php代码:
if ($_POST["alt"] == "Edit") {
# Dados do form
$idequip = $_GET['id'];
$contrato = $_POST['contrato'];
$transmi = $_POST['transmissor'];
$ip = $_POST['ipaddress'];
$local = $_POST['local']; //tipo_equip
$obs = $_POST['obs'];
$usado = $_POST['usado'];
echo "<br />";
print_r($ip);
# Atualiza dados do equipamento mestre
# desenvolvendo
$res = mysql_query("UPDATE equipment SET idtorre='$transmi', ip='$ip', tipo_equip='$local', obs='$obs', usado_cliente='$usado' WHERE id='$idequip'") or die("Erro na query: atualização equipamento mestre.");
#header("Location: equipamento_adm.php?return=3&ip=$control");
exit;
}
全部!
推荐答案
这是一个简单的多维数组,你可以像这样检索你的值:
It a simple multidimensional array, you can retrieve your value like this :
$ip = $_POST['ipaddress'];
$justip = $ip['abcd'][0];
现在只有 $ justip中的ip地址
变量。
您应该阅读有关数组的文档: http://ch.php.net/manual/en/language.types.array.php
You should maybe read the documentation about arrays : http://ch.php.net/manual/en/language.types.array.php
这篇关于如何只获取IP地址/子网的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!