Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

php parsing sequence

Status
Not open for further replies.

mettodog

Vendor
Jul 11, 2000
94
0
0
US
When you insert a header ( require ('whatever.php') )
does php parse that code, and then insert the results in the page it was called for, or does it insert the plain php code and then parse the whole page? Because if it just inserted the plain php, and then parsed the whole thing i was going to do this:

in index.php-
$text1 = "Hello All"
$text2 = "Yo Danny Boy!"
require ('header.php')

blah blah blah~~~~~~

in header.php-
echo "$text1";
echo "$text2";

blah blah blah~~~ (i hope my code is correct, im new to php)

Would that work? Or would i have to use global variables if it parses the header then inserts it?

Also, could you explain the syntax for global variables?

 
PHP parses all the code at once, so imagine an include or a require as 'placeholders', and your code is actually all in one place. The one thing to remember is that a require() is only parsed once, whereas an include() can be parsed several times--for example if it is inside a loop.

You need to also remember that PHP drops out of parsing mode when loading includes and requires (otherwise you would have trouble with plain HTML), so you need to open and close your '<?php ?>' tags again inside the included file.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top