...or anything falsy:

if(!preg_match('#^(https?|ftp)://#', $src)) // returns number of matches (0 or 1) or false in case of error

    Either one works. Thank you very much.

      Hi, I'm kinda stuck. Currently when you click upload it will spit out number of images found and a list of the names of those images. If I have multiple html files how do I show the names of html files and images associated to that html file? Currently, I have this:

      "3 images found:"
      a1.gif
      a2.gif
      3.gif

      But, if I have multiple html files I want to show:

      6 images found:

      test1.html test2.html etc...
      a1.gif a4.gif
      a2.gif a5.gif
      a3.gif a6.gif

      I know I would want to use a foreach loop but I'm not sure how/what to use in the html portion. Would I need to write a function for the PHP code below? I have a feeling my code is not the elegant solution.

      /* PHP /

      $dir = "path/";
      $imgs = glob($dir . "*.{jpg,gif,png}", GLOB_BRACE);
      
      foreach($imgs as $img){ 
          $arr1[] = pathinfo( $img,PATHINFO_BASENAME ); 
      };
      
      foreach (glob("path/*.{html, htm}", GLOB_BRACE) as $path){ 
      	$dom = new DOMDocument;
      	$dom->preserveWhiteSpace = false;
      	@$dom->loadHTMLFile($path);
      	$images = $dom->getElementsByTagName('img');
      
      foreach ($images as $image) {
      	$src = $image->getAttribute( 'src' );
      	if(!preg_match('#^(https?|ftp)://#', $src)) {
                	       $arr2[] = pathinfo( $src,PATHINFO_BASENAME ); 
      	};	
               };  	
       };
      
      $diff = array_diff($arr1, $arr2);
      
      $img_dir = new RecursiveDirectoryIterator("path/");
      foreach(new RecursiveIteratorIterator($img_dir) as $file) {
      	if (in_array(basename($file), $diff)) { 
      
         $old_dir = 'path/' .$img_dir . '/images/'. basename($file);
         $new_dir = 'path/' .$img_dir . '/new_folder/'. basename($file);
      
         if (isset($_POST['submit'])) {
      	$selected_radio = $_POST['group'];
      	if ($selected_radio == 'save'){
      		mkdir('path/' .$img_dir . '/new_folder/', 0700); 
      		rename($old_dir,$new_dir);
      
      	 }else if($selected_radio == 'delete'){
      		 unlink($old_dir);				
      	  };
      	};
       };
      };
      };
      

      /* HTML /

      <form method="post">
      <input type="file" name="zip_file" />
      <input type="submit" name="upload" value="upload" />
      <?php
      if (isset($_POST['upload'])) {
      foreach(){ // Here I want to show names of html files and a list of found images associated with that html file

              	 echo '<div>'.count($diff). '  images found: '. '</div>';
      	 echo '<div><ul><li>'. implode('</li><li>', $diff) .'</li></ul></div>';
               };
      }else if (isset($_POST['submit'])){
      	$selected_radio = $_POST['group'];
      	if ($selected_radio == 'save'){
      		echo '<div>'.count($diff). ' images saved to folder!'. '</div>';
      			}else if($selected_radio == 'delete'){
      				echo '<div>'.count($diff). ' images deleted!'. '</div>';
      	};
      };				

      };
      ?>

        <input type="radio" name="group" value="save">Save to folder<br />
        <input type="radio" name="group" value="delete">Delete<br /><br />
        <input type="submit" name="submit"  value="submit" />

      </form>

        Figured it out. Was way easier than I thought.

          I ran into a problem after I echo the file names and image names. How would I compare 1 array against 3 different ones? For example:

          $arr1 = array(a,b,c,d)
          $arr2 = array(a,b,c,d,e)
          $arr3 = array(a,b,c,d,e,f)
          $arr4 = array(a,b,c,d,e,g)

          I want to compare:

          $arr1 and $arr2
          $arr1 and $arr3
          $arr1 and $arr4

          And echo result.

          So, I did this:

          $diff = array_diff($arr1, $arr2, $arr3, $arr4);

          But that just compares everything.

            To make three separate comparisons ... make three separate comparisons.

              So, I tried this and came back with 0 image files found. Not sure what else I need to do.

              $diff1 = array_diff($arr1, $arr2);
              $diff2 = array_diff($arr1, $arr3);
              $diff3 = array_diff($arr1, $arr4);

              $result = array_values($diff1, $diff2, $diff3);
              //echo $result;

              $img_dir = new RecursiveDirectoryIterator("path/");
              foreach(new RecursiveIteratorIterator($img_dir) as $file) {
              if (in_array(basename($file), $result)) {
              //code to handle found image files
              };

                crump;11012357 wrote:

                So, I tried this and came back with 0 image files found. Not sure what else I need to do.

                I'm not sure either. what do you want to do?

                also, are you sure this

                $result = array_values($diff1, $diff2, $diff3);
                echo $result;

                results in "0 image files found"? It should result in "Array" (and possibly a Notice about array-to-string conversion).

                  Sorry, long day and I think I may be over-thinking this. If there are certain number of found unused images in test1.html these same images would also show up in test2.html. Unless, of course, if some of those images are used in test2.html then they wouldn't be "unused" any longer. Wouldn't there be fewer images found in test2.html than test1.html as a result? I'm getting duplicate number of images in both html files.

                    traq;11012365 wrote:

                    I'm not sure either. what do you want to do?

                    also, are you sure this

                    $result = array_values($diff1, $diff2, $diff3);
                    echo $result;

                    results in "0 image files found"? It should result in "Array" (and possibly a Notice about array-to-string conversion).

                    Actually, it would result in a null, as well as an error message about how [man]array_values[/man] expects exactly one parameter instead of the three that it was given (presumably [man]array_merge[/man] was intended).

                      could you [man]print_r/man everything and show us what results you are getting? then, show us what you expect/want?

                      Weedpacket wrote:

                      Actually, it would result in a null, as well as an error message about how array_values expects exactly one parameter instead of the three that it was given (presumably array_merge was intended).

                      right... misread that (long day also)

                        I think I got it to work. Thanks and sorry for the confusion.

                        I have one other question...last question I really hope. Is there a way to set a variable to take any directory path?

                        For instance this code:

                        $dir = "$dir_path//";
                        $images = glob($dir . "*.{jpg,gif,png}", GLOB_BRACE);

                        can be set so that $dir can take any directory?

                        $dir = "$dir_path//"; or "$dir_path*/";

                        Thanks!

                          try it?

                          the * means nothing to the variable itself, but [man]glob/man will interpret it as a wildcard, yes - just as if you'd typed it as an argument directly.

                            Still can't get it work.

                            $a = "$dir_path*/*/";
                            $b = "$dir_path*/";  
                            $dir = $a || $b; $imgs = glob($dir . "*.{jpg,gif,png}", GLOB_BRACE); echo $dir;

                            Also tried these variations with no luck:
                            $dir $a or $b;
                            $dir .= $b .= $a;
                            $dir = $b = $a;

                              This:

                              $dir = $a || $b;

                              doesn't make sense, since that's just going to set $dir to boolean TRUE.

                              This:

                              $dir $a or $b;

                              doesn't make sense, since it's not even valid PHP syntax.

                              This:

                              $dir .= $b .= $a;

                              doesn't make sense, since you're going to be changing the value of $b and then assigning that new value (which is just $a appended to the end of $b) to $dir.

                              This:

                              $dir = $b = $a;

                              doesn't make sense, since you're overwriting the value stored in $b with that which is stored in $a, and then assigning that value to $dir.

                              Can you show us example values for $a and $b, and then show us what the resulting $dir string should look like?

                                Thanks for the explanation.

                                The values for $a and $b are:
                                $a = "$dir_path//";
                                $b = "$dir_path*/";

                                I want $dir to take either

                                this directory path:
                                $dir_path//

                                or this directory path:
                                $dir_path*/

                                So, that I can get images with this code.

                                $imgs = glob($dir . "*.{jpg,gif,png}", GLOB_BRACE);
                                foreach($imgs as $img){
                                $arr[] = pathinfo( $img,PATHINFO_BASENAME );
                                };

                                  How can a string ($dir) be two different values simultaneously? The answer is it cannot.

                                  Instead, you'll probably want to perform two different glob() operations on $a and $b separately and then combine the two resulting arrays together into one ($imgs).

                                    Thanks for pointing me in the right direction! Got it figured out now.

                                      I'm having issue echoing my result.

                                      I have this:

                                      $success1 = rename($old_dir,$new_dir);
                                      $success2 = unlink($old_dir);

                                      Then in my form I have this:

                                                                      if (isset($_POST['submit'])){
                                      				$selected_radio = $_POST['rgroup'];
                                      
                                      			if (($selected_radio == 'save') && ($success1 == true)){ 
                                      				  echo 'saved!';
                                      				  }else{
                                      					  echo 'not saved!';
                                      					  };
                                      
                                      
                                      		    if (($selected_radio == 'delete') && ($success2 == true)){ 
                                      				    echo 'deleted!';
                                      			     }else{
                                      					  echo 'not deleted!';
                                      					  };
                                      		};
                                      

                                      My radio inputs:

                                      <input type="radio" name="rgroup" value="save" />
                                      <input type="radio" name="rgroup" value="delete" />

                                      When I click save I get these two messages:

                                      "saved!" and "not deleted!" Why is "not deleted!" showing up?

                                        How can PHP delete something you've just renamed?

                                        EDIT: That is, without telling it to delete the new name you've given something. In other words, do you not understand what "rename" means?