我正在阅读PHP中页面的源代码。该页面中有一个隐藏的输入字段<input type="hidden" name="session_id" value=
。PHP代码读取网页的源代码并从标签获取属性
$url = 'URL HERE';
$needle = '<input type="hidden" name="session_id" value=';
$contents = file_get_contents($url);
if(strpos($contents, $needle)!== false) {
echo 'found';
} else {
echo 'not found';
}
我想读取隐藏字段值。
+1 $'xpath-> query' – anubhava 2012-01-03 17:43:24
+1刚刚删除我自己的答案赞成xpath解决方案:-) – favo 2012-01-03 17:44:12
@imi这不是一个有效的HTML文档。你需要用我描述的相同技术来抑制警告[在这个答案中](http://stackoverflow.com/a/6090728/417562)。 – lonesomeday 2012-01-03 17:53:27