[thelist] Global variables in functions?

Joel Konkle-Parker jjk3 at msstate.edu
Tue Aug 19 23:48:05 CDT 2003


This looks like something very fundamental that I'm just not understanding...

I have a PHP script that declares some variables and a body() function, then
includes a template script that integrates body() and prints the page.

When I do this:

--
  $url = 'http://server/script.php?'.$_SERVER[QUERY_STRING];
  $output = file_get_contents ($url);

function body() {
  echo $output;
}
--

body() ends up empty. But when I do this:

--
function body() {

  $url = 'http://server/script.php?'.$_SERVER[QUERY_STRING];
  $output = file_get_contents ($url);
  echo $output;

}
--

it works fine.

The ultimate goal here is to read the resulting page from $url, strip off
everything but the contents of <body></body>, and print the result.

What am I missing here?

(btw, any tips on the line-stripping?)


--
Joel Konkle-Parker
Webmaster [Ballsome.com]

Phone     [662-518-1636]
E-mail    [jjk3 at msstate.edu]


More information about the thelist mailing list