Answer the question
In order to leave comments, you need to log in
How to write a regular expression for substituting field values?
The PHP script receives a named array of values id_field=its value, and the html code of the form in which there are fields with id="id_field"
Fields can be of different types - for example, and
Inside the tags of the fields there can be additional parameters such as style classes and other things, their number is in advance unknown.
We need to replace value for input and text for textarea focusing only on their id using a regular expression - please help me to compose it correctly.
For example, the array has fields:
mytitle='My title'
mytext='My text'
and the form code in the variable is
<form action="add.php" name="blog" id="blog" enctype="multipart/form-data" method="post"><input type="text" name="mytitle" id="mytitle" value="Мое название" placeholder="Название статьи" required><textarea name="mytext" id="mytext" placeholder="Текст" required>Мой текст</textarea><p><input type="submit" value="Отправить" title="Отправить"></form>
<form action="add.php" name="blog" id="blog" enctype="multipart/form-data" method="post"><input type="text" name="mytitle" id="mytitle" value="" placeholder="Название статьи" required><textarea name="mytext" id="mytext" placeholder="Текст" required></textarea><p><input type="submit" value="Отправить" title="Отправить"></form>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question