0

Пока решение такое:

$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);
2
  • по хорошему id должно быть уникально в файле. Вот и стоит ли городить программу, если можно поменять в тектовом редакторе?
    – splash58
    30 ноя 2020 в 21:53
  • 1
    приходит html, который нужно конвертировать в pdf и при этом заполнить необходимые поля 30 ноя 2020 в 21:55

1 ответ 1

1

Вероятно вам лучше использовать класс 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());

Run code

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.