我有一个 html 文件作为 php 中的字符串加载,我需要获取 HTML 字符串中输入元素的值。有人可以帮我构建一个函数,该函数采用输入元素的名称并返回其值吗?
这是我想做的功能的一个例子:
function getVal($name){
$htmlStr = "<form action = \"action.php\"><input type=\"hidden\" name=\"command\" value=\"123456\">
<input type=\"hidden\" name=\"quantity\" value=\"1\">
<input type=\"hidden\" name=\"user_mode\" value=\"1\">
<input type=\"hidden\" name=\"stock\" value=\"-1255303070\">
<input type=\"hidden\" name=\"id\" value="429762082">
<input type=\"hidden\" name=\"pidm\" value=\"2\"></form>";
// I'd like to get the value of $name here probably using preg_match
return $value; //returns 123456
}
$val = getVal("命令"); //val 应该是 123456。
任何伊达斯?谢谢