1

I'm trying to parse some HTML. This is my code:

xml_parse_into_struct($p, $initpage, $values);
foreach ($values as $key => $val) {
    if (($val['tag'] == 'INPUT') && ($val['attributes']['name'] == 'authenticity_token')) {
        $token = $val['attributes']['value'];
        break;
    }
}
echo $token;

No problems with the curl or the XML parsing... I know that $values includes the goodies, as print_r($values) wil output, amongst other things, this:

[48] => Array
   (
       [tag] => INPUT
       [type] => complete
       [level] => 8
       [attributes] => Array
            (
                [NAME] => authenticity_token
                [TYPE] => hidden
                [VALUE] => d76a4bec329537ac3322
            )

    )

When I try running the code, however, I get this error:

PHP Notice: Undefined variable: token in /media/.sda3/pjotr/scripts/tweet.php on line 49

0

1 Answer 1

2

Keys are case sensitive. You check for name, which doesn't match NAME. Same goes for value, of course, so you need to fix that too.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.