3v4l.org

run code in 300+ PHP versions simultaneously
<?php $the_mysql_result = array(); $the_mysql_result[0]['id'] = "1"; $the_mysql_result[0]['address']="www.example.com/page1"; $the_mysql_result[0]['title']="Page 1"; $the_mysql_result[0]['content']="The quick dog jumps over the lazy dog."; $the_mysql_result[0]['image']="image_1.jpg"; $the_mysql_result[1]['id'] = "2"; $the_mysql_result[1]['address']="www.example.com/page2"; $the_mysql_result[1]['title']="Page 2"; $the_mysql_result[1]['content']="The best thing about morning is breakfast."; $the_mysql_result[1]['image']="image_2.jpg"; $the_mysql_result[2]['id'] = "3"; $the_mysql_result[2]['address']="www.example.com/page3"; $the_mysql_result[2]['title']="Page 3"; $the_mysql_result[2]['content']="Hotdogs are great ballpark food."; $the_mysql_result[2]['image']="image_3.jpg"; $query="dog"; foreach($the_mysql_result as $results) { $content = $results['content']; $row_occurences = explode($query,$content); foreach($row_occurences as $an_occurence) { $content=$an_occurence.$query; echo '<li class="media"> <a class="pull-left" href="'.$results['address'].'"> <img class="media-object thumbnail" src="'.$results['image'].'" style="height:100px !important"> </a> <div class="media-body"> <h4 class="media-heading"><a href="'.$results['address'].'">'.$results['title'].'</a></h4> <p>...'.str_replace($query,'<strong>'.$query.'</strong>', substr($content,strpos($content,$query)-25,160)).'...</p> </div> </li>'; $total++; } }
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
<li class="media"> <a class="pull-left" href="www.example.com/page1"> <img class="media-object thumbnail" src="image_1.jpg" style="height:100px !important"> </a> <div class="media-body"> <h4 class="media-heading"><a href="www.example.com/page1">Page 1</a></h4> <p>...The quick <strong>dog</strong>...</p> </div> </li> Warning: Undefined variable $total in /in/2FZ9I on line 46 <li class="media"> <a class="pull-left" href="www.example.com/page1"> <img class="media-object thumbnail" src="image_1.jpg" style="height:100px !important"> </a> <div class="media-body"> <h4 class="media-heading"><a href="www.example.com/page1">Page 1</a></h4> <p>... <strong>dog</strong>...</p> </div> </li><li class="media"> <a class="pull-left" href="www.example.com/page1"> <img class="media-object thumbnail" src="image_1.jpg" style="height:100px !important"> </a> <div class="media-body"> <h4 class="media-heading"><a href="www.example.com/page1">Page 1</a></h4> <p>....<strong>dog</strong>...</p> </div> </li><li class="media"> <a class="pull-left" href="www.example.com/page2"> <img class="media-object thumbnail" src="image_2.jpg" style="height:100px !important"> </a> <div class="media-body"> <h4 class="media-heading"><a href="www.example.com/page2">Page 2</a></h4> <p>...out morning is breakfast.<strong>dog</strong>...</p> </div> </li><li class="media"> <a class="pull-left" href="www.example.com/page3"> <img class="media-object thumbnail" src="image_3.jpg" style="height:100px !important"> </a> <div class="media-body"> <h4 class="media-heading"><a href="www.example.com/page3">Page 3</a></h4> <p>...Hot<strong>dog</strong>...</p> </div> </li><li class="media"> <a class="pull-left" href="www.example.com/page3"> <img class="media-object thumbnail" src="image_3.jpg" style="height:100px !important"> </a> <div class="media-body"> <h4 class="media-heading"><a href="www.example.com/page3">Page 3</a></h4> <p>... are great ballpark food.<strong>dog</strong>...</p> </div> </li>
Output for 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.31, 7.4.0 - 7.4.25, 7.4.27 - 7.4.33
<li class="media"> <a class="pull-left" href="www.example.com/page1"> <img class="media-object thumbnail" src="image_1.jpg" style="height:100px !important"> </a> <div class="media-body"> <h4 class="media-heading"><a href="www.example.com/page1">Page 1</a></h4> <p>...The quick <strong>dog</strong>...</p> </div> </li> Notice: Undefined variable: total in /in/2FZ9I on line 46 <li class="media"> <a class="pull-left" href="www.example.com/page1"> <img class="media-object thumbnail" src="image_1.jpg" style="height:100px !important"> </a> <div class="media-body"> <h4 class="media-heading"><a href="www.example.com/page1">Page 1</a></h4> <p>... <strong>dog</strong>...</p> </div> </li><li class="media"> <a class="pull-left" href="www.example.com/page1"> <img class="media-object thumbnail" src="image_1.jpg" style="height:100px !important"> </a> <div class="media-body"> <h4 class="media-heading"><a href="www.example.com/page1">Page 1</a></h4> <p>....<strong>dog</strong>...</p> </div> </li><li class="media"> <a class="pull-left" href="www.example.com/page2"> <img class="media-object thumbnail" src="image_2.jpg" style="height:100px !important"> </a> <div class="media-body"> <h4 class="media-heading"><a href="www.example.com/page2">Page 2</a></h4> <p>...out morning is breakfast.<strong>dog</strong>...</p> </div> </li><li class="media"> <a class="pull-left" href="www.example.com/page3"> <img class="media-object thumbnail" src="image_3.jpg" style="height:100px !important"> </a> <div class="media-body"> <h4 class="media-heading"><a href="www.example.com/page3">Page 3</a></h4> <p>...Hot<strong>dog</strong>...</p> </div> </li><li class="media"> <a class="pull-left" href="www.example.com/page3"> <img class="media-object thumbnail" src="image_3.jpg" style="height:100px !important"> </a> <div class="media-body"> <h4 class="media-heading"><a href="www.example.com/page3">Page 3</a></h4> <p>... are great ballpark food.<strong>dog</strong>...</p> </div> </li>
Output for 4.3.0 - 4.3.11, 4.4.0 - 4.4.9, 5.0.0 - 5.0.5, 5.1.0 - 5.1.6, 5.2.0 - 5.2.1, 5.2.7 - 5.2.17, 7.3.32 - 7.3.33, 7.4.26
<li class="media"> <a class="pull-left" href="www.example.com/page1"> <img class="media-object thumbnail" src="image_1.jpg" style="height:100px !important"> </a> <div class="media-body"> <h4 class="media-heading"><a href="www.example.com/page1">Page 1</a></h4> <p>...The quick <strong>dog</strong>...</p> </div> </li><li class="media"> <a class="pull-left" href="www.example.com/page1"> <img class="media-object thumbnail" src="image_1.jpg" style="height:100px !important"> </a> <div class="media-body"> <h4 class="media-heading"><a href="www.example.com/page1">Page 1</a></h4> <p>... <strong>dog</strong>...</p> </div> </li><li class="media"> <a class="pull-left" href="www.example.com/page1"> <img class="media-object thumbnail" src="image_1.jpg" style="height:100px !important"> </a> <div class="media-body"> <h4 class="media-heading"><a href="www.example.com/page1">Page 1</a></h4> <p>....<strong>dog</strong>...</p> </div> </li><li class="media"> <a class="pull-left" href="www.example.com/page2"> <img class="media-object thumbnail" src="image_2.jpg" style="height:100px !important"> </a> <div class="media-body"> <h4 class="media-heading"><a href="www.example.com/page2">Page 2</a></h4> <p>...out morning is breakfast.<strong>dog</strong>...</p> </div> </li><li class="media"> <a class="pull-left" href="www.example.com/page3"> <img class="media-object thumbnail" src="image_3.jpg" style="height:100px !important"> </a> <div class="media-body"> <h4 class="media-heading"><a href="www.example.com/page3">Page 3</a></h4> <p>...Hot<strong>dog</strong>...</p> </div> </li><li class="media"> <a class="pull-left" href="www.example.com/page3"> <img class="media-object thumbnail" src="image_3.jpg" style="height:100px !important"> </a> <div class="media-body"> <h4 class="media-heading"><a href="www.example.com/page3">Page 3</a></h4> <p>... are great ballpark food.<strong>dog</strong>...</p> </div> </li>
Output for 5.2.2 - 5.2.6
<li class="media"> <a class="pull-left" href="www.example.com/page1"> <img class="media-object thumbnail" src="image_1.jpg" style="height:100px !important"> </a> <div class="media-body"> <h4 class="media-heading"><a href="www.example.com/page1">Page 1</a></h4> <p>......</p> </div> </li><li class="media"> <a class="pull-left" href="www.example.com/page1"> <img class="media-object thumbnail" src="image_1.jpg" style="height:100px !important"> </a> <div class="media-body"> <h4 class="media-heading"><a href="www.example.com/page1">Page 1</a></h4> <p>... <strong>dog</strong>...</p> </div> </li><li class="media"> <a class="pull-left" href="www.example.com/page1"> <img class="media-object thumbnail" src="image_1.jpg" style="height:100px !important"> </a> <div class="media-body"> <h4 class="media-heading"><a href="www.example.com/page1">Page 1</a></h4> <p>......</p> </div> </li><li class="media"> <a class="pull-left" href="www.example.com/page2"> <img class="media-object thumbnail" src="image_2.jpg" style="height:100px !important"> </a> <div class="media-body"> <h4 class="media-heading"><a href="www.example.com/page2">Page 2</a></h4> <p>...out morning is breakfast.<strong>dog</strong>...</p> </div> </li><li class="media"> <a class="pull-left" href="www.example.com/page3"> <img class="media-object thumbnail" src="image_3.jpg" style="height:100px !important"> </a> <div class="media-body"> <h4 class="media-heading"><a href="www.example.com/page3">Page 3</a></h4> <p>......</p> </div> </li><li class="media"> <a class="pull-left" href="www.example.com/page3"> <img class="media-object thumbnail" src="image_3.jpg" style="height:100px !important"> </a> <div class="media-body"> <h4 class="media-heading"><a href="www.example.com/page3">Page 3</a></h4> <p>... are great ballpark food.<strong>dog</strong>...</p> </div> </li>

preferences:
286.23 ms | 409 KiB | 460 Q