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){ 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.4, 8.3.6
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>" } Warning: Undefined array key 0 in /in/3OpEV on line 15 Deprecated: strpos(): Passing null to parameter #2 ($needle) of type string is deprecated in /in/3OpEV on line 15 Warning: Undefined array key 1 in /in/3OpEV on line 15 Deprecated: strpos(): Passing null to parameter #2 ($needle) of type string is deprecated in /in/3OpEV on line 15 Warning: Undefined array key 2 in /in/3OpEV on line 15 Deprecated: strpos(): Passing null to parameter #2 ($needle) of type string is deprecated in /in/3OpEV on line 15 ....other stuff.... </script>0
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 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>" } Warning: Undefined array key 0 in /in/3OpEV on line 15 Deprecated: strpos(): Passing null to parameter #2 ($needle) of type string is deprecated in /in/3OpEV on line 15 Warning: Undefined array key 1 in /in/3OpEV on line 15 Deprecated: strpos(): Passing null to parameter #2 ($needle) of type string is deprecated in /in/3OpEV on line 15 Warning: Undefined array key 2 in /in/3OpEV on line 15 Deprecated: strpos(): Passing null to parameter #2 ($needle) of type string is deprecated in /in/3OpEV on line 15 ....other stuff.... </script>0
Output for 8.0.0 - 8.0.30
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>" } Warning: Undefined array key 0 in /in/3OpEV on line 15 Warning: Undefined array key 1 in /in/3OpEV on line 15 Warning: Undefined array key 2 in /in/3OpEV on line 15 ....other stuff.... </script>0
Output for 7.3.16 - 7.3.31, 7.4.0 - 7.4.25, 7.4.27 - 7.4.33
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/3OpEV 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/3OpEV on line 15 Notice: Undefined offset: 0 in /in/3OpEV 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/3OpEV on line 16 Notice: Undefined offset: 1 in /in/3OpEV 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/3OpEV on line 15 Notice: Undefined offset: 1 in /in/3OpEV 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/3OpEV on line 16 Notice: Undefined offset: 2 in /in/3OpEV 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/3OpEV on line 15 Notice: Undefined offset: 2 in /in/3OpEV 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/3OpEV on line 16 ....other stuff.... </script>0
Output for 7.3.32 - 7.3.33, 7.4.26
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>" } ....other stuff.... </script>0
Output for 7.0.0 - 7.0.20, 7.1.0 - 7.1.20, 7.2.0 - 7.2.33
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/3OpEV on line 15 Notice: Undefined offset: 0 in /in/3OpEV on line 16 Notice: Undefined offset: 1 in /in/3OpEV on line 15 Notice: Undefined offset: 1 in /in/3OpEV on line 16 Notice: Undefined offset: 2 in /in/3OpEV on line 15 Notice: Undefined offset: 2 in /in/3OpEV on line 16 ....other stuff.... </script>0

preferences:
161.33 ms | 403 KiB | 173 Q