filter - PHP Online

Form of PHP Sandbox

Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php in the places where the PHP script should be executed.



Your result can be seen below.

Result of php executing





Full code of filter.php

  1. <?php
  2.  
  3. $str = '<div>
  4.          <span class="all-the-same-classes">example text</span> 
  5.          <span class="all-the-same-classes">example text</span>
  6.          <span class="all-the-same-classes">pic.example.com/A1B2C3</span>
  7.         </div>';
  8.  
  9. $get_only_span    = str_replace(array("<div>","</div>"),'',$str);
  10. $explode_to_array = explode("<span",$get_only_span);
  11. $rm_empty_values  = array_filter(array_map('trim', $explode_to_array));
  12.  
  13. $new_span = '<div>';
  14. foreach($rm_empty_values as $key){
  15.      if (strpos($key, 'pic.example.com') == false) {
  16.         $new_span .= '<span '.$key."\n";
  17.  
  18.      }
  19. }
  20. $new_span .= '</div>';
  21.  
  22. print_r($new_span);
File Description
  • filter
  • PHP Code
  • 24 Jul-2020
  • 637 Bytes
You can Share it: