将html输入表转换为PHP数组

时间:2022-09-27 08:59:21

I am trying to get the information from a html table into an php array. It is very easy to do with the following method:

我试图从html表中获取信息到php数组。使用以下方法很容易:

function getdata($table)
{
    $DOM = new DOMDocument;
    $DOM->loadHTML($table);

    $items = $DOM->getElementsByTagName('tr');

    function tdrows($elements)
    {
        $str = "";
        foreach ($elements as $element)
        {
            $str .= $element->nodeValue . ", ";
        }
        return $str;
    }
    foreach ($items as $node)
    {
        echo tdrows($node->childNodes) . "<br />";
    }
}

The problem I am now facing is the content of the table has html inputs and I want just the value of those inputs. The table is of the form:

我现在面临的问题是表的内容有html输入,我只想要那些输入的值。该表的形式如下:

<table>
<tr><td><input type="text" /></td><td><input type="text" /></td><td><div class="add">add</div></td></tr>
</table>

Will I be able to modify the current function to accomplish this or should I try another approach

我能否修改当前函数来完成此操作,还是应该尝试其他方法

1 个解决方案

#1


0  

As PHP is server-side, you will not be able to get the value of the input unless you submit this inputted value to the server, for example using post or get when the form is submitted. You should use Javascript if you want the value of the input without having to submit the form. If this doesn't answer your question please try to ask it more clearly : )

由于PHP是服务器端,除非您将此输入值提交给服务器,否则您将无法获取输入值,例如使用post或获取表单时获取。如果您想要输入的值而不必提交表单,则应该使用Javascript。如果这不能回答您的问题,请尝试更清楚地询问:)

#1


0  

As PHP is server-side, you will not be able to get the value of the input unless you submit this inputted value to the server, for example using post or get when the form is submitted. You should use Javascript if you want the value of the input without having to submit the form. If this doesn't answer your question please try to ask it more clearly : )

由于PHP是服务器端,除非您将此输入值提交给服务器,否则您将无法获取输入值,例如使用post或获取表单时获取。如果您想要输入的值而不必提交表单,则应该使用Javascript。如果这不能回答您的问题,请尝试更清楚地询问:)