3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $html = '<!--HEAD--><p class="listing-grp-title">Top Ranked Offers</p><!--HEAD--> <!--WRAPPERSTART--><div><table><!--WRAPPERSTART--> <tr class="{% if forloop.counter|divisibleby:2 %}even{% else %}odd{% endif %}"> <td class="rank">&#35; {{forloop.counter}}</td> <td class="logo"> <img src="{{ad.display_url}}" width="120" height="40" alt="Aig Sml"/> </td> <td> <p class="offer">{{ad.headline}}</p> {{ad.body|safe}} </td> <td> <img src="images/arrow.png" width="14" height="18" alt=""/> </td> <td class="end"> <a href="#"><img class="button" src="images/sml-btn.png" width="112" height="30" alt=""/></a> </td> </tr> <!--WRAPPEREND--></table></div><!--WRAPPEREND-->'; $sub= 'sub_0_'; echo _format_special_tags($html,$sub); function _format_special_tags($html,$sub) { //where sub is sub_1_ or similar $tags = array(); $outer= "{% if forloop.counter = ".$sub."range.0 %}"; $end_outer = "{% endif %}"; $header = $this->_return_between('<!--HEAD-->',$html); $wrapper_start = $this->_return_between('<!--WRAPPERSTART-->',$html); $wrapper_end = $this->_return_between('<!--WRAPPEREND-->',$html); $html = $outer.(($header)?$header:'').(($wrapper_start)?$wrapper_start:'').$end_outer.$html.$outer.(($wrapper_end)?$wrapper_end:'').$end_outer; } function _return_between($tag,$subject) { $split = explode($tag,$subject,3); return isset($split[1])?$split[1]:false; }
Output for 7.0.0 - 7.1.0
Fatal error: Uncaught Error: Using $this when not in object context in /in/0DVXi:31 Stack trace: #0 /in/0DVXi(24): _format_special_tags('<!--HEAD--><p c...', 'sub_0_') #1 {main} thrown in /in/0DVXi on line 31
Process exited with code 255.
Output for 5.0.0 - 5.6.28
Fatal error: Using $this when not in object context in /in/0DVXi on line 31
Process exited with code 255.
Output for 4.3.2 - 4.4.9
Fatal error: Call to a member function on a non-object in /in/0DVXi on line 31
Process exited with code 255.
Output for 4.3.0 - 4.3.1
Fatal error: Call to a member function on a non-object in /in/0DVXi on line 31