_
_ Handy PHP
_
_
Tutorials, Scripts, Information And Other Resources arrow Forum
Tuesday, 07 October 2008
_

Refer A Friend using Revolution Money Exchange
Resource Menu
Handy PHP Store
Free Domain Name
PHP Functions
PHP Downloads
PHP Newsfeeds
PHP Tutorials
Webmaster Tools
User Login
TalkPHP
Get friendly help with your PHP problems for free.
www.talkphp.com
The PHP Resource Index
Handy PHP
Free PHP Help!

FireBoard
Welcome, Guest
Please Login or Register.    Lost Password?
Adding Content From An External File In HTML (1 viewing) (1) Guest
Go to bottom Post Reply Favoured: 0
TOPIC: Adding Content From An External File In HTML
#300
vujsa (Admin)
Admin
Posts: 139
graph
User Online Now Click here to see the profile of this user
Adding Content From An External File In HTML 10 Months ago Karma: 4  
According to my statistics, someone performed a search engine query for the following:
"adding content from external file in html"

Assuming the the developer doesn't want to use FRAMES or IFRAMES to insert an external source into their webpage, a scripting language like PHP will need to be used.

In most cases, to get the server to use PHP, the file has to have the .php file extension. If you are working with existing HTML files, they'll need to be converted to PHP. There is already a tutorial available for this: Converting HTML to PHP Basic Tutorial

Once you have your files converted or new files created with what every HTML you want to use to display your content as you normally do, you can begin to insert data from external text, HTML, PHP, or other files.

Imagine that you have a very basic webpage like so:
index.php
Code:

<html> <head> <title>Handy PHP Insert External Data Example</title> <meta name="description" content=""> <meta name="keywords" content=""> <meta name="author" content="vujsa"> </head> <body bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080"> Hello World! </body> </html>
The result would look like this:
QUOTE:
Hello World!
Then you could create a simple text file like so: greeting.txt
Code:

Thank you for visiting Handy PHP!
If you modified the webpage like so: index.php
Code:

<html> <head> <title>Handy PHP Insert External Data Example</title> <meta name="description" content=""> <meta name="keywords" content=""> <meta name="author" content="vujsa"> </head> <body bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080"> Hello World!<br /> <?php include('greeting.txt'); ?> </body> </html>
Which would display the following:
QUOTE:
Hello World! Thank you for visiting Handy PHP!
It is important to note that data in the external file will be handle according to how you format it no matter what the file extension is. So greeting.txt could be named greeting html and display the same. If the file has HTML in it, the browser WILL convert that raw HTML into the displayed information you normally see in your browser. If you have PHP in your external file, then the server will execute that PHP code even if the file ends with something other than .php. Using this type of external insertion allows for sections of you website that is identical on every page to be in a separate file allowing for only one file edit to change every page instead of having to open edit and save every file individually. This is great for site navigation menus that are the same on every page but may change from time to time. Hope this helps. vujsa
 
Report to moderator   Logged Logged  
  The administrator has disabled public write access.
Go to top Post Reply
Powered by FireBoardget the latest posts directly to your desktop

_
 
_
_
© 2008 Handy PHP