Hi friends,
i have this code

<html>
  <head>
  <title></title>
  </head>
  <body>

<?php

$nurl = count($_POST['url']);

for($i=0; $i<$nurl; $i++) {

	$string = file_get_contents($_POST['url'][$i]);

		if ( preg_match_all("/title=\"My custom title\"/", $string, $matches) ) {

				if (count($matches) > 0) {
					echo 'FOUND<br />';
					echo $_POST['url'][$i] . '<br />';				

				} 

			} else {

					echo 'not found';
					echo  '<script type="text/JavaScript">setTimeout(\'window.close()\', 1000)</script>';
			}
		}	
?>

</body>
</html>

I would want to print the URLs found by preg_match_all and close the windows if not found.

With my current code, the page is always closed.
I don't understand why. I've already tried the break to exit from for loop but isn't the solution.

Can you help me? thanks!
j.

    someone can suggest to me please?

      One possible problem I see is that if any single $POST['url'] entry does not match, then you'll call the window-closing code. I might try restructuring it this way:

      <?php
      $found = false;
      $nurl = count($_POST['url']);
      for($i=0; $i<$nurl; $i++) {
      	$string = file_get_contents($_POST['url'][$i]);
      	if ( preg_match_all("/title=\"My custom title\"/", $string, $matches) ) {
      		if (count($matches) > 0) {
      			$found = true;
      			echo 'FOUND<br />';
      			echo $_POST['url'][$i] . '<br />';                
      } } } if(!$found) { echo 'not found'; echo '<script type="text/JavaScript">setTimeout(\'window.close()\', 1000)</script>'; } ?>

        PS: I'd also add a check on the value of $string to see if file_get_contents() is actually getting anything. (Maybe your config has allow_url_fopen turned off? [which would generate a warning/error if you have all error reporting enabled])

          now it works! thank you very much 🙂

            Write a Reply...