I'm not sure if this can be done with preg_replace, but this is what I have so far
$string='
<div class="row">
<section> [1] </section>
<section> [2] </section>
<section> [5] </section>
</div>';
function searchArray($myarray, $id) {
foreach ($myarray as $item) {
if ($item[$id] == $id)
return $item['name'];
}
return false;
}
So I need to run $string through preg_replace where each var between [] will correspond to an actual id stored in multidimensional array. This is where function searchArray() comes in. Basically runs string, replace [] with actual id's and print name of the field. All this needs to happen when I submit form in one pass.