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
1 Answer 1
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.
answered Dec 14, 2012 at 18:26
GolezTrol
116k19 gold badges186 silver badges215 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
default