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); if(count($row_occurences)>1) { 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>'; } } }
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, 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.24 - 5.5.35, 5.6.8 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.20, 7.2.0 - 7.2.33, 7.3.12 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.27, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 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><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/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 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 <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/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/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:
263.69 ms | 405 KiB | 312 Q