3v4l.org

run code in 300+ PHP versions simultaneously
<?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){ echo $arr[$i]; 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 $str; Echo substr_count(strip_tags($str), "example");
Output for 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.7
<p class="example">example</p> Warning: Undefined array key 0 in /in/L301T on line 17 Deprecated: strpos(): Passing null to parameter #2 ($needle) of type string is deprecated in /in/L301T on line 17 <p class="example" style="visibility:hidden">example</p> Warning: Undefined array key 1 in /in/L301T on line 17 Deprecated: strpos(): Passing null to parameter #2 ($needle) of type string is deprecated in /in/L301T on line 17 <script type="text/javascript">var example = 1 Warning: Undefined array key 2 in /in/L301T on line 17 Deprecated: strpos(): Passing null to parameter #2 ($needle) of type string is deprecated in /in/L301T on line 17 ....other stuff.... </script>0
Output for 8.0.0 - 8.0.30
<p class="example">example</p> Warning: Undefined array key 0 in /in/L301T on line 17 <p class="example" style="visibility:hidden">example</p> Warning: Undefined array key 1 in /in/L301T on line 17 <script type="text/javascript">var example = 1 Warning: Undefined array key 2 in /in/L301T on line 17 ....other stuff.... </script>0
Output for 7.3.0 - 7.3.31, 7.4.0 - 7.4.25, 7.4.27 - 7.4.33
<p class="example">example</p> Notice: Undefined offset: 0 in /in/L301T on line 17 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/L301T on line 17 Notice: Undefined offset: 0 in /in/L301T on line 18 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/L301T on line 18 <p class="example" style="visibility:hidden">example</p> Notice: Undefined offset: 1 in /in/L301T on line 17 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/L301T on line 17 Notice: Undefined offset: 1 in /in/L301T on line 18 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/L301T on line 18 <script type="text/javascript">var example = 1 Notice: Undefined offset: 2 in /in/L301T on line 17 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/L301T on line 17 Notice: Undefined offset: 2 in /in/L301T on line 18 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/L301T on line 18 ....other stuff.... </script>0
Output for 7.3.32 - 7.3.33, 7.4.26
<p class="example">example</p> <p class="example" style="visibility:hidden">example</p> <script type="text/javascript">var example = 1 ....other stuff.... </script>0
Output for 7.0.0 - 7.0.20, 7.1.0 - 7.1.25, 7.2.0 - 7.2.33
<p class="example">example</p> Notice: Undefined offset: 0 in /in/L301T on line 17 Notice: Undefined offset: 0 in /in/L301T on line 18 <p class="example" style="visibility:hidden">example</p> Notice: Undefined offset: 1 in /in/L301T on line 17 Notice: Undefined offset: 1 in /in/L301T on line 18 <script type="text/javascript">var example = 1 Notice: Undefined offset: 2 in /in/L301T on line 17 Notice: Undefined offset: 2 in /in/L301T on line 18 ....other stuff.... </script>0

preferences:
172.33 ms | 403 KiB | 189 Q