从循环外定义的函数传递变量但在循环内调用

i want to call a function which is defined outside the loop but called inside the loop and then access a variable from that function definition which is outside the loop to inside the loop every time loop runs
here is the database connectivity that contains while loop and a funtion calling and then accessing the $second_trim variable defined in ""function page($h)"" inside the while loop

  <html>
  <head>
  <title></title>
 </head>     
 <body>
 <?php
 $getquery = mysql_query("SELECT * FROM table WHERE $construct LIMIT $start, $per_page");
 while($runrows = mysql_fetch_assoc($getquery))
 {
 $title = $runrows ['Title'];
 $url = $runrows ['URL'];
 page($url);
 echo "<div style='clear: both;position:relative;border:1px solid #A5BEBE;background-color:   white;'>
 $second_trim</div>";
}
function page($h){
$i=fopen($h,"r");
$contents=stream_get_contents($i);
fclose($i);
$contents=strtolower($contents);

$start='<div';

$start_pos=strpos($contents,$start);
$first_trim=substr($contents,$start_pos);

$stop='</div>';
$stop_pos=strpos($first_trim,$stop);

$second_trim=substr($first_trim,0,$stop_pos);
}
?>
</body>
</html>

the while loop fetch url from the database and pass through "page($url)" function called inside the loop to defined function "function page($h)"outside the loop it will get required content in $second_trim that will displayed inside the loop in echo statement every time it runs but i m getting the error like Fatal error: Call to undefined function crawl_page() their is some syntax problem i m facing that i cant find after alot of search is their any can do this plz help me out

You need to define your function -> function page($h){...} before your loop. Second, return the $second_trim at the end of your function, and third set your function call to your variable

...your html...
<?php

function page($h){
      $i=fopen($h,"r");
      $contents=stream_get_contents($i);
      fclose($i);
      $contents=strtolower($contents);
      $start='<div';
      $start_pos=strpos($contents,$start);
      $first_trim=substr($contents,$start_pos);   
      $stop='</div>';
      $stop_pos=strpos($first_trim,$stop);
      $second_trim=substr($first_trim,0,$stop_pos);

      //return the value
      return $second_trim;
}


$getquery = mysql_query("SELECT * FROM table WHERE $construct LIMIT $start, $per_page");
while($runrows = mysql_fetch_assoc($getquery)){
      $title = $runrows ['Title'];
      $url = $runrows ['URL'];

      //save the function returned value to variable
      $second_trim = page($url);

      echo "<div style='clear: both;position:relative;border:1px solid #A5BEBE;background-color:   white;'>
      $second_trim</div>";
}
?>
...your html...