Page 1 of 1
Php parsing
Posted: Tue Mar 02, 2004 11:47 pm
by cjoe
G'Day, im a total newbie to the php and dev community in general, so im sorry if i broken any etiquette. This is my first post, thanks for spending time to read this, i just hope one day i'll be able to help someone else.
I was wondering how php was parsed (i use Apache), specifically how included files were parsed. For example if i called and included file with the extension .php (or any other for that matter), will the include file be parsed as part of the original php script or will it be set aside to be added to the clients html file.
I have the latest major build of PHP and am running it as a Apache module, (please excuse if i have used poor terminology, im new to this) with the latest version of Apache on Mandrake 9.
Posted: Tue Mar 02, 2004 11:53 pm
by markl999
It will be parsed at the point you include/require it.
So if the included file has some echo's in it for example, those echo's will be displayed at the same point you include the file.
If you are asking this one just TRY...
Posted: Wed Mar 03, 2004 12:50 am
by apple
<?php
$page_name = 'Your WebPage Title';
include ('header.inc'); //PageName is also variable in your header.inc
// IF SENTENCE
echo "HELLO WORLD";
// IF TABLE
echo '<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>hello world</td>
</tr>
</table>';
include ('footer.inc'); // The footpage
?>
Posted: Wed Mar 03, 2004 2:15 am
by no_memories
header parses in xml
http://forums.thexvector.us/viewtopic.php?t=5
body parses other required files
http://forums.thexvector.us/viewtopic.php?t=4
this is basic, but the principle is sound. These forums are generated in a similar way, but with a database's data.
Posted: Wed Mar 03, 2004 3:46 am
by McGruff
An included file basically becomes an addition to the script where the include call was made, as if it had been written there.
It will not be parsed unless the parser finds < ?php ? > tags in the file.
So, if you include a php file (ie enclosed with tags) it becomes part of the calling script. The included code has access to all the vars in the scope of the include call, and can return values to the calling script.
Including an html file is basically a print command: unless you are output buffering, the html immediately gets served up to the client. The html file can embed php echo commands ( < ?php echo $var; ? >) to add some dynamic content - anything in tags gets parsed.
Including html (or xml etc) templates is a very important technique which allows you to keep business logic and presentation logic separate. As a rule, php scripts should never contain any html - all they do is define a bunch of vars. A page is printed by including a template with some embedded echo calls. The template applies formatting and layout to the bare vars.
That's a slightly simplified outline (you can mix php and html in a presentation layer - but never in the biz logic) but if you're just starting out that'll have to wait till later.
Thanks
Posted: Tue Mar 16, 2004 8:36 pm
by cjoe
Thanks very much for your help everyone! Appreciate it. I'm going along nicely now!