doulai2573 2011-03-03 13:12
浏览 53
已采纳

如何只获取IP地址/子网

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)

The result:

$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.!

The Whole Code:

HTML Page jQuery plugins included:

<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>

Now my Action php code:

 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;
 }

That all!

  • 写回答

3条回答 默认 最新

  • dqhsv0147421 2011-03-03 13:13
    关注

    It a simple multidimensional array, you can retrieve your value like this :

    $ip = $_POST['ipaddress'];    
    $justip = $ip['abcd'][0];
    

    Now there's only the ip address in the $justip variable.

    You should maybe read the documentation about arrays : http://ch.php.net/manual/en/language.types.array.php

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥100 求三轴之间相互配合画圆以及直线的算法
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 自己瞎改改,结果现在又运行不了了
  • ¥15 链式存储应该如何解决
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站