Welcome to WebmasterWorld Guest from

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)

5+ Year Member

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.
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)

10+ Year Member

Yes, you can use the include() [php.net] function.


8:00 pm on Nov 20, 2006 (gmt 0)

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

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:


if you have php that you want executed within it.

Featured Threads

Hot Threads This Week

Hot Threads This Month