3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $mysql_result[0]['id']="1"; $mysql_result[1]['id']="2"; $mysql_result[2]['id']="3"; $mysql_result[0]['address']="www.example.com/page1"; $mysql_result[1]['address']="www.example.com/page2"; $mysql_result[2]['address']="www.example.com/page3"; $mysql_result[0]['title']="Page 1"; $mysql_result[1]['title']="Page 2"; $mysql_result[2]['title']="Page 3"; $mysql_result[0]['content']="The quick dog jumps over the lazy dog."; $mysql_result[1]['content']="The best thing about morning is breakfast."; $mysql_result[2]['content']="Hotdogs are great ballpark food."; $mysql_result[0]['image']="image1.jpg"; $mysql_result[1]['image']="image2.jpg"; $mysql_result[2]['image']="image3.jpg"; $query="dog"; foreach($mysql_result as $a_row) { $content = str_replace($query,"my_un1qu3_r3pl4c3m3nt_".$query,$a_row['content']); $occurences = explode("my_un1qu3_r3pl4c3m3nt_",$content); if(count($occurences)>1) { foreach($occurences as $results) { $content=$results['content']; 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 5.4.0 - 7.1.0
Warning: Illegal string offset 'content' in /in/5EaN0 on line 36 Warning: Illegal string offset 'address' in /in/5EaN0 on line 39 Warning: Illegal string offset 'image' in /in/5EaN0 on line 40 Warning: Illegal string offset 'address' in /in/5EaN0 on line 43 Warning: Illegal string offset 'title' in /in/5EaN0 on line 43 <li class="media"> <a class="pull-left" href="T"> <img class="media-object thumbnail" src="T" style="height:100px !important"> </a> <div class="media-body"> <h4 class="media-heading"><a href="T">T</a></h4> <p>...T...</p> </div> </li> Warning: Illegal string offset 'content' in /in/5EaN0 on line 36 Warning: Illegal string offset 'address' in /in/5EaN0 on line 39 Warning: Illegal string offset 'image' in /in/5EaN0 on line 40 Warning: Illegal string offset 'address' in /in/5EaN0 on line 43 Warning: Illegal string offset 'title' in /in/5EaN0 on line 43 <li class="media"> <a class="pull-left" href="d"> <img class="media-object thumbnail" src="d" style="height:100px !important"> </a> <div class="media-body"> <h4 class="media-heading"><a href="d">d</a></h4> <p>...d...</p> </div> </li> Warning: Illegal string offset 'content' in /in/5EaN0 on line 36 Warning: Illegal string offset 'address' in /in/5EaN0 on line 39 Warning: Illegal string offset 'image' in /in/5EaN0 on line 40 Warning: Illegal string offset 'address' in /in/5EaN0 on line 43 Warning: Illegal string offset 'title' in /in/5EaN0 on line 43 <li class="media"> <a class="pull-left" href="d"> <img class="media-object thumbnail" src="d" style="height:100px !important"> </a> <div class="media-body"> <h4 class="media-heading"><a href="d">d</a></h4> <p>...d...</p> </div> </li> Warning: Illegal string offset 'content' in /in/5EaN0 on line 36 Warning: Illegal string offset 'address' in /in/5EaN0 on line 39 Warning: Illegal string offset 'image' in /in/5EaN0 on line 40 Warning: Illegal string offset 'address' in /in/5EaN0 on line 43 Warning: Illegal string offset 'title' in /in/5EaN0 on line 43 <li class="media"> <a class="pull-left" href="H"> <img class="media-object thumbnail" src="H" style="height:100px !important"> </a> <div class="media-body"> <h4 class="media-heading"><a href="H">H</a></h4> <p>...H...</p> </div> </li> Warning: Illegal string offset 'content' in /in/5EaN0 on line 36 Warning: Illegal string offset 'address' in /in/5EaN0 on line 39 Warning: Illegal string offset 'image' in /in/5EaN0 on line 40 Warning: Illegal string offset 'address' in /in/5EaN0 on line 43 Warning: Illegal string offset 'title' in /in/5EaN0 on line 43 <li class="media"> <a class="pull-left" href="d"> <img class="media-object thumbnail" src="d" style="height:100px !important"> </a> <div class="media-body"> <h4 class="media-heading"><a href="d">d</a></h4> <p>...d...</p> </div> </li>
Output for 4.3.0 - 5.2.1, 5.2.7 - 5.3.29
<li class="media"> <a class="pull-left" href="T"> <img class="media-object thumbnail" src="T" style="height:100px !important"> </a> <div class="media-body"> <h4 class="media-heading"><a href="T">T</a></h4> <p>...T...</p> </div> </li><li class="media"> <a class="pull-left" href="d"> <img class="media-object thumbnail" src="d" style="height:100px !important"> </a> <div class="media-body"> <h4 class="media-heading"><a href="d">d</a></h4> <p>...d...</p> </div> </li><li class="media"> <a class="pull-left" href="d"> <img class="media-object thumbnail" src="d" style="height:100px !important"> </a> <div class="media-body"> <h4 class="media-heading"><a href="d">d</a></h4> <p>...d...</p> </div> </li><li class="media"> <a class="pull-left" href="H"> <img class="media-object thumbnail" src="H" style="height:100px !important"> </a> <div class="media-body"> <h4 class="media-heading"><a href="H">H</a></h4> <p>...H...</p> </div> </li><li class="media"> <a class="pull-left" href="d"> <img class="media-object thumbnail" src="d" style="height:100px !important"> </a> <div class="media-body"> <h4 class="media-heading"><a href="d">d</a></h4> <p>...d...</p> </div> </li>
Output for 5.2.2 - 5.2.6
<li class="media"> <a class="pull-left" href="T"> <img class="media-object thumbnail" src="T" style="height:100px !important"> </a> <div class="media-body"> <h4 class="media-heading"><a href="T">T</a></h4> <p>......</p> </div> </li><li class="media"> <a class="pull-left" href="d"> <img class="media-object thumbnail" src="d" style="height:100px !important"> </a> <div class="media-body"> <h4 class="media-heading"><a href="d">d</a></h4> <p>......</p> </div> </li><li class="media"> <a class="pull-left" href="d"> <img class="media-object thumbnail" src="d" style="height:100px !important"> </a> <div class="media-body"> <h4 class="media-heading"><a href="d">d</a></h4> <p>......</p> </div> </li><li class="media"> <a class="pull-left" href="H"> <img class="media-object thumbnail" src="H" style="height:100px !important"> </a> <div class="media-body"> <h4 class="media-heading"><a href="H">H</a></h4> <p>......</p> </div> </li><li class="media"> <a class="pull-left" href="d"> <img class="media-object thumbnail" src="d" style="height:100px !important"> </a> <div class="media-body"> <h4 class="media-heading"><a href="d">d</a></h4> <p>......</p> </div> </li>