Welcome to WebmasterWorld Guest from 50.19.190.144

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Write Contents with PHP

Write Contents with PHP

     
12:10 pm on Nov 20, 2006 (gmt 0)

Junior Member

5+ Year Member

joined:May 18, 2006
posts:68
votes: 0


I currently write contents to a file using something like this addpage.php :-
$headpart = "<?php require(\"../homeincludes/config.php\");?>\n<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n<html>\n<head>\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\" />\n";

Problem is this becomes a pain when I have to make any global changes as I have to edit the source code for the script.

Question: is there anyway that I can place this code within a txt file and just open it, read it then write it to the page.
Example:
head.txt
body.txt
footer.txt
This would make it easier to change then by simply opening the txt file and making the changes.

5:23 pm on Nov 20, 2006 (gmt 0)

Preferred Member

10+ Year Member

joined:Aug 6, 2005
posts:575
votes: 0


Yes, you can use the include() [php.net] function.
8:00 pm on Nov 20, 2006 (gmt 0)

Senior Member

WebmasterWorld Senior Member eelixduppy is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Nov 12, 2005
posts:5966
votes: 0


Including it is fine, yes, however if it's going to be a .txt file the php won't be interpreted AND you may be leaving sensitive material out in the open.

You may want to call those included files something like:

head.inc.php

if you have php that you want executed within it.