Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
php regexp:查找带有隐藏输入的表单&;添加另一个输入_Php_Html_Regex_Forms - Fatal编程技术网

php regexp:查找带有隐藏输入的表单&;添加另一个输入

php regexp:查找带有隐藏输入的表单&;添加另一个输入,php,html,regex,forms,Php,Html,Regex,Forms,我需要帮助解决这个问题: 我有一个HTML字符串和输出的HTML代码,我需要搜索所有的形式,其中是特定的输入(隐藏与给定的名称和值)。在这个隐藏输入之后,我需要添加另一个具有给定参数的输入(只有值是动态的) 谢谢回复 //对不起,我的英语不好…你可以这样做 <?php $html = file_get_contents('form.html'); if (preg_match('/\<.+? name="other" .+?\>/', $html, $match)) {

我需要帮助解决这个问题:

我有一个HTML字符串和输出的HTML代码,我需要搜索所有的形式,其中是特定的输入(隐藏与给定的名称和值)。在这个隐藏输入之后,我需要添加另一个具有给定参数的输入(只有值是动态的)

谢谢回复


//对不起,我的英语不好…

你可以这样做

<?php

$html = file_get_contents('form.html');

if (preg_match('/\<.+? name="other" .+?\>/', $html, $match)) {
    $element = $match[0];
    $element .= '<input type="hidden" name="appended" value="etry">';
    $html = str_replace($match[0], $element, $html);
}

echo $html;