1

我正在尝试从动态创建的 jquery 表单中解析 JSON 数据。用户可以单击“添加步骤”按钮添加任意数量(或少量)的表单字段(包括附加媒体链接),但我不知道如何在 PHP 中处理此类数据。这是我期望收到的一些示例表单 $_POST 数据:

Array
(
    [1] => Array //1, 2, 3, 4 are the position for this particular 'step' on the page
        (
            [Counter] => 1
            [Title] => step one
            [Step] => description
            [Links] => Array
                (
                    [0] => link 1
                    [1] => link 2
                )

        )

    [2] => Array
        (
            [Counter] => 2
            [Title] => step two
            [Step] => some kind of description
            [Links] => Array
                (
                    [0] => link 2
                )

        )

    [3] => Array
        (
            [Counter] => 3
            [Title] => step three
            [Step] => description (another one)
        )

    [4] => Array
        (
            [Counter] => 4
            [Title] => Step four
            [Step] => a lame description
            [Links] => Array
                (
                    [0] => link 1
                    [1] => link 2
                )

        )

    [tutorial_name] => tutorial name? jesus?
    [tutorial_description] => some useless description
    [tutorial_toolsused] => waste of a tools used
    [tutorial_keywords] => waste of keywords
)

知道如何最好地处理此类数据(正则表达式,foreach)吗?我应该避免使用 post 协议吗?

任何帮助将不胜感激!

4

2 回答 2

1

您可以使用is_array()PHP中的函数来实现解决方案。

基本上,是这样的。

foreach($_POST as $value) {
    if(is_array($value)) {
        //process your data here. i.e. the counter, step, links, title
}
于 2013-02-02T06:53:40.410 回答
0

如果碰巧有人感兴趣。再次感谢!

<?php
foreach($_POST as $value) {
        if(is_array($value)) {
            //process your data here. i.e. the counter, step, links, title
            echo $value['Position'] . "<br /><br />";
            echo $value['Counter'] . "<br /><br />";
            echo $value['Title'] . "<br /><br />";
            echo $value['Step'] . "<br /><br />";
            if(isset($value['Links'])){
                if(is_array($value['Links'])){
                    foreach($value['Links'] as $link){
                        echo $link . "<br /><br />";
                    }
                }
            }
        }
    }
?>
于 2013-02-02T08:40:33.537 回答