dqx76962 2018-04-19 03:56
浏览 37

数组返回,枚举或其他解决方案?

I'm having trouble identifying each row of this array ... would it be possible to enumerate or otherwise be able to pull a specific array field?

My code is:

<?php

/*
    Generic function to fetch all input tags (name and value) on a page
Useful when writing automatic login bots/scrapers
*/
function get_input_tags($html)
{
    $post_data = array();

    // a new dom object
    $dom = new DomDocument; 

    //load the html into the object
    $dom->loadHTML($html); 
    //discard white space
    $dom->preserveWhiteSpace = false; 

    //all input tags as a list
    $input_tags = $dom->getElementsByTagName('input'); 

    //get all rows from the table
    for ($i = 0; $i < $input_tags->length; $i++) 
    {
        if( is_object($input_tags->item($i)) )
        {
            $name = $value = '';
            $name_o = $input_tags->item($i)->attributes->getNamedItem('name');
            if(is_object($name_o))
            {
                $name = $name_o->value;

                $value_o = $input_tags->item($i)->attributes->getNamedItem('value');
                if(is_object($value_o))
                {
                    $value = $input_tags->item($i)->attributes->getNamedItem('value')->value;
                }

                $post_data[$name] = $value;
            }
        }
    }

    return $post_data;
}

/*
    Usage
*/

error_reporting(~E_WARNING);
$html = file_get_contents("https://secure.donman.net.au/client/ozchild/Donate.aspx");

echo "<pre>";
print_r(get_input_tags($html));
echo "</pre>";

?>

Generate the result

[radInMemDiscloseAmount] => No
[txtInMemOfAddress] => 
[txtInMemOfSuburb] => 
[txtInMemOfState] => 
[txtInMemOfPostCode] => 
[txtInHonorOfName] => 
[txtInHonorOfAddress] => 
[txtInHonorOfSuburb] => 
[txtInHonorOfState] => 
[txtInHonorOfPostCode] => 
[HonorEventType] => gf_other_choice
[HonorEventTypeOtherText] => Other

how can I have something like this?

    [0][radInMemDiscloseAmount] => No
    [1][txtInMemOfAddress] => 
    [2][txtInMemOfSuburb] => 
    [3][txtInMemOfState] => 
    [4][txtInMemOfPostCode] => 
    [5][txtInHonorOfName] => 
    [6][txtInHonorOfAddress] => 
    [7][txtInHonorOfSuburb] => 
    [8][txtInHonorOfState] => 
    [9][txtInHonorOfPostCode] => 
    [10][HonorEventType] => gf_other_choice
    [11][HonorEventTypeOtherText] => Other

how can I have something like this? or some way to identify array rows? I'm having trouble identifying each row of this array ... would it be possible to enumerate or otherwise be able to pull a specific array field?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 python的qt5界面
    • ¥15 无线电能传输系统MATLAB仿真问题
    • ¥50 如何用脚本实现输入法的热键设置
    • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
    • ¥30 深度学习,前后端连接
    • ¥15 孟德尔随机化结果不一致
    • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
    • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
    • ¥15 谁有desed数据集呀
    • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100