Как найти input в строке по id и добавить в него value посредством регулярки в PHP?
Пока решение такое:
$html = str_replace(
"<input id='printed_name' type='text' class='forma_input' required='' style='position: relative;top: -8px;'>",
"<input id='printed_name' type='text' class='forma_input' required='' style='position: relative;top: -8px;' value='1234'>", $str);
Ответы (1 шт):
Автор решения: ordman
→ Ссылка
Вероятно вам лучше использовать класс DomDocument
$html = <<<HTML
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>header</title>
</head>
<body>
<input id='printed_name' type='text' class='forma_input' required='' style='position: relative;top: -8px;'>
</body>
</html>
HTML;
$doc = new DOMDocument();
$doc->loadHtml($html);
$el = $doc->getElementById('printed_name');
$el->setAttribute( "value", "1234" );
var_dump($doc->saveHTML());