3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $template = ' <div style="border:1px solid blue;padding:10px;"> <h1>"[item_title]"</h1> <p>"[item_text]"</p> <a href="[item_link]">[item_link]</a> </div> <div style="border:1px solid blue;padding:10px;"> <h1>[item_title]</h1> <p>[item_text]</p> <a href="[item_link]">[item_link]</a> </div> '; /// ITEM 1 $title = 'title 1'; $text = 'text text text'; $link = 'http://www.google.com'; /// ITEM 2 $title = 'title 2'; $text = 'text2 text2 text2'; $link = 'http://www.google.com'; $regex = array( '/\[\item_title\]/is' => $title, '/\[\item_text\]/is' => $text, '/\[\item_link\]/is' => $link, ); foreach($regex as $keys => $values) { $temp = preg_replace($keys, $values, $template); } echo $temp;
Output for 4.3.0 - 7.1.0
<div style="border:1px solid blue;padding:10px;"> <h1>"[item_title]"</h1> <p>"[item_text]"</p> <a href="http://www.google.com">http://www.google.com</a> </div> <div style="border:1px solid blue;padding:10px;"> <h1>[item_title]</h1> <p>[item_text]</p> <a href="http://www.google.com">http://www.google.com</a> </div>