Php parsing

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
cjoe
Forum Newbie
Posts: 2
Joined: Tue Mar 02, 2004 11:47 pm
Location: Australia

Php parsing

Post 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.
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post 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.
apple
Forum Newbie
Posts: 21
Joined: Wed Mar 03, 2004 12:50 am
Contact:

If you are asking this one just TRY...

Post 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

?>
User avatar
no_memories
Forum Contributor
Posts: 145
Joined: Sun Feb 01, 2004 7:12 pm
Location: New York City

Post 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.
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post 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.
cjoe
Forum Newbie
Posts: 2
Joined: Tue Mar 02, 2004 11:47 pm
Location: Australia

Thanks

Post by cjoe »

Thanks very much for your help everyone! Appreciate it. I'm going along nicely now!
Post Reply