3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $str = '<p class="example">example</p> <p class="example" style="visibility:hidden">example</p> <script type="text/javascript">var example = 1 ....other stuff.... </script>'; $arr = explode(PHP_EOL, $str); var_dump($arr); for($i = 0; $i < count($arr); $i++){ if(strpos("hidden", $arr[$i]) === false){ unset($arr[$i]); } if(strpos("<script", $arr[$i]) === false){ while(!strpos("</script", $arr[$i]) === false){ unset($arr[$i]); $i++; } } } $str = implode(PHP_EOL, $arr); Echo substr_count(strip_tags($str), "example");
based on YMd7q
Output for 7.3.0beta1
array(5) { [0]=> string(30) "<p class="example">example</p>" [1]=> string(59) " <p class="example" style="visibility:hidden">example</p>" [2]=> string(50) " <script type="text/javascript">var example = 1 " [3]=> string(22) " ....other stuff...." [4]=> string(12) " </script>" } Notice: Undefined offset: 0 in /in/FWCg9 on line 15 Deprecated: strpos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in /in/FWCg9 on line 15 Notice: Undefined offset: 0 in /in/FWCg9 on line 16 Deprecated: strpos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in /in/FWCg9 on line 16 Notice: Undefined offset: 1 in /in/FWCg9 on line 15 Deprecated: strpos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in /in/FWCg9 on line 15 Notice: Undefined offset: 1 in /in/FWCg9 on line 16 Deprecated: strpos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in /in/FWCg9 on line 16 Notice: Undefined offset: 2 in /in/FWCg9 on line 15 Deprecated: strpos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in /in/FWCg9 on line 15 Notice: Undefined offset: 2 in /in/FWCg9 on line 16 Deprecated: strpos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in /in/FWCg9 on line 16 0
Output for 5.6.0 - 5.6.30, 7.0.0 - 7.3.0alpha1
array(5) { [0]=> string(30) "<p class="example">example</p>" [1]=> string(59) " <p class="example" style="visibility:hidden">example</p>" [2]=> string(50) " <script type="text/javascript">var example = 1 " [3]=> string(22) " ....other stuff...." [4]=> string(12) " </script>" } Notice: Undefined offset: 0 in /in/FWCg9 on line 15 Notice: Undefined offset: 0 in /in/FWCg9 on line 16 Notice: Undefined offset: 1 in /in/FWCg9 on line 15 Notice: Undefined offset: 1 in /in/FWCg9 on line 16 Notice: Undefined offset: 2 in /in/FWCg9 on line 15 Notice: Undefined offset: 2 in /in/FWCg9 on line 16 0
Output for hhvm-3.15.4
array(5) { [0]=> string(30) "<p class="example">example</p>" [1]=> string(59) " <p class="example" style="visibility:hidden">example</p>" [2]=> string(50) " <script type="text/javascript">var example = 1 " [3]=> string(22) " ....other stuff...." [4]=> string(12) " </script>" } Notice: Undefined index: 0 in /in/FWCg9 on line 15 Notice: Undefined index: 0 in /in/FWCg9 on line 16 Notice: Undefined index: 1 in /in/FWCg9 on line 15 Notice: Undefined index: 1 in /in/FWCg9 on line 16 Notice: Undefined index: 2 in /in/FWCg9 on line 15 Notice: Undefined index: 2 in /in/FWCg9 on line 16 0