我正在閱讀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