I have this code:
<body>
<label id="Label1052">The loop is below</label>
<img id="Image733" src="logo-2.png">
<!--the loop--><div id="theLoop">
<label id="Label736">{title}</label>
<label id="Label737">{date}</label>
<label id="Label739">{content}</label>
</div><!--the loop-->
</body>
Expected output:
<body>
<label id="Label1052">The loop is below</label>
<img id="Image733" src="logo-2.png">
<!--the loop--><div id="theLoop">
<label id="Label736">Post 1</label>
<label id="Label737">Jan 1</label>
<label id="Label739">The content</label>
</div>
<div id="theLoop">
<label id="Label736">Post 2</label>
<label id="Label737">Jan 5</label>
<label id="Label739">The content</label>
</div>
<div id="theLoop">
<label id="Label736">Post 3</label>
<label id="Label737">Jan 6</label>
<label id="Label739">The content</label>
</div><!--the loop-->
</body>
Here is my PHP:
// contains the content above
$markup = "<body>...</body>";
// find the loop and get the contents that has tokens
$match = preg_match("<!--the loop-->(.*)<!--the loop-->");
for (var i;i<itemCount;i++) {
$item = items[i];
// start to replace content - there are many tokens - I have a function
$newContent = replaceTokensInContent($item, $match);
$myArray.push($newContent);
}
$newContent = $myArray.join();
// put the content back into the markup
$updated_markup = preg_replace("<!--the loop-->(.*)<!--the loop-->", $newContent, $markup);
I want to get the contents between both tokens <!--the loop-->
and then replace tokens in that multiple times (I have a function) and then put that populated string back into the main string again.
I know how to do this regex in JavaScript but not PHP.