I
I
Ivan2016-03-12 06:40:48
PHP
Ivan, 2016-03-12 06:40:48

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>

it is necessary that after the replacement this code becomes like this
<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

1 answer(s)
T
trefferr, 2016-03-12
@trefferr

As an option, place the labels {title}, {text}, then replace them

str_ireplace(array('метки'), array('данные на которые нужно заменить'), 'текст где нужно заменить');

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question