I have the following text
this is line one
[gallery]
this is line two
[gallery]
this is line three
I also have the following code in php
$text = 'this is line one [gallery] this is line two [gallery] this is line three';
$gallery = array('gallery name1', 'gallery name2');
foreach ($gallery as $key => $val) {
$text = preg_replace('#\[gallery\]#si', $val, $text);
}
I want to replace the first [gallery] with the first value of array $gallery and the second [gallery] with the second value of array $gallery.
How can i do this?