Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
display content from external file into HTML
Old 05-12-2012, 05:04 PM display content from external file into HTML
Average Talker

Posts: 23
Trades: 0
I am trying to simply display the content from my test.txt file into my HTML page. My test.txt file includes some html, something like this below:

Code:
My name is <b>tee louis</b>.  Welcome to my website.
I want to display that in my HTML DIV section. (Reason is, I don't wanna have to update my HTML page everytime I need to update the content of the text file.

I don't understand how to use PHP with HTML. I know how to create a php code page. And I've found code that gives examples on how to create the PHP script, but once you have the script how do you use it in your html?

can someone provide me an example on how to do this? Thank you
talytech is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 05-12-2012, 05:19 PM Re: display content from external file into HTML
chrishirst's Avatar
Defies a Status

Posts: 43,957
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Server Side Includes

http://www.candsdesign.co.uk/article.../php-includes/

http://www.w3schools.com/php/php_includes.asp
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 05-13-2012, 08:18 AM Re: display content from external file into HTML
Average Talker

Posts: 23
Trades: 0
I read up on PHP include and either I'm stupid or its extremely complex. I included the php code in my html page like this:

Code:
<body>
<div id="wrapper">
<div id="wrapthis">
 <div id="boxholder">
  <table border="0">
   <tr>
    <div id="header">
   </tr>
  </table>
 </div>
  
  
  <div id="content">
   <?php include "textfiles/theband.txt"; ?>
  </div>
</div>  
</div>
      
</body>
</html>
it returned nothing. I am totally confused. Do I have to create a seperate .php page that includes this line ..
Code:
<?php include "textfiles/theband.txt"; ?>
and then call the php page in the html page? I'm lost. Can someone please help me.
talytech is offline
Reply With Quote
View Public Profile
 
Old 05-13-2012, 08:54 AM Re: display content from external file into HTML
chrishirst's Avatar
Defies a Status

Posts: 43,957
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
To run PHP code the document extension MUST be .php or you must have set other extensions to be parsed as PHP.
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 05-13-2012, 09:06 AM Re: display content from external file into HTML
King Spam Talker

Posts: 1,090
Name: Paul W
Trades: 0
Just to stress Chris's point - at the simplest, you will have two files, say a.php and b.txt

a.php will be as you've done above, b.txt can contain anything. The effect of the include is the same as cutting and pasting the contents into a.php
__________________
Great music:
Please login or register to view this content. Registration is FREE



Please login or register to view this content. Registration is FREE
PaulW is offline
Reply With Quote
View Public Profile
 
Old 05-13-2012, 10:53 AM Re: display content from external file into HTML
Average Talker

Posts: 23
Trades: 0
Ok.. this is really frustrating me ... I still get nothing returned in my html page

so .. here's my .php page called "content.php"

PHP code:
Code:
<?php include "textfiles/theband.txt"; ?>
My text file is in a folder called textfiles and the filename is theband.txt


And here's my html:

Code:
<body>
<div id="wrapper">
<div id="wrapthis">
 <div id="boxholder">
  <table border="0">
   <tr>
    <div id="header">
   </tr>
  </table>
 </div>
  
  
  <div id="content">
   <?php include "content.php"; ?>
  </div>
</div>  
</div>
      
</body>
</html>
I don't know how this should work together. I don't know if my php code is correct. I don't know if my html code is correct.

Can someone please provide me an example. This seems easy which is why I'm frustrated. I don't understand how this all fits together... TEXTFILE ..PHP ..HTML
talytech is offline
Reply With Quote
View Public Profile
 
Old 05-13-2012, 12:34 PM Re: display content from external file into HTML
chrishirst's Avatar
Defies a Status

Posts: 43,957
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
what do you see when looking at the rendered sorce code?

And where is the "textfiles" directory in relation to the document.
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 05-13-2012, 03:14 PM Re: display content from external file into HTML
lizciz's Avatar
Super Spam Talker

Posts: 845
Name: Mattias Nordahl
Location: Sweden
Trades: 0
I think you missunderstood. The page which you refer to as your html page, that is the page which needs to have the .php extension, not the file you are trying to include. For example:

your_page.php could contain
HTML Code:
<html>
<head>
    ...
</head>
<body>
    ...
    <?php include "textfiles/theband.txt"; ?>
    ...
</body>
</html>
Also, you have forgot to close your #header div with a </div>.
__________________
Your answers will only be as good as your question. Formulate it well and give all the necessary information.
lizciz is offline
Reply With Quote
View Public Profile Visit lizciz's homepage!
 
Old 05-13-2012, 06:38 PM Re: display content from external file into HTML
Average Talker

Posts: 23
Trades: 0
oh so basically, rename band.html to band.php?

is that all? I'm totally brand new to php. I didn't know i can set it up like I set my html page up. what about the CSS styles sheet. that will still be linked and used to format the html too? Something like this?

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd"> 
<html>
<head>
<title>Love District Live</title>
<link rel="stylesheet" type="text/css" href="css/style.css" />

<script src="swfobject.js" type="text/javascript"></script>
<script type="text/javascript">
var params = {
   loop: "false",
   wmode: "transparent",
   bgcolor: "#000000"
};
swfobject.embedSWF("header.swf", "header", "900", "300", "6.0.65", false, false, params, false);
</script>

<script type="text/javascript">
var params = {
   loop: "false",
   bgcolor: "#000000"
};
swfobject.embedSWF("theband.swf", "theband", "900", "480", "8.0.0", false, false, params, false);
</script>
<!-- JavaScripts-->
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/s3Slider.js"></script>
<script type="text/javascript">
    $(document).ready(function() {
        $('#slider').s3Slider({
            timeOut: 3000
        });
    });
</script>
</head>

<body>
<div id="wrapper">
<div id="wrapthis">
 <div id="boxholder">
  <table border="0">
   <tr>
    <div id="header">
   </tr>
  </table>
 </div>
  
  
  <div id="content">
   <?php include "textfiles/theband.txt"; ?>
  </div>
 
</div>  
</div>
      
</body>
</html>
talytech is offline
Reply With Quote
View Public Profile
 
Old 05-14-2012, 02:27 AM Re: display content from external file into HTML
King Spam Talker

Posts: 1,090
Name: Paul W
Trades: 0
Quote:
Originally Posted by talytech View Post
oh so basically, rename band.html to band.php?

Yes - that was what I was trying to say in my earlier reply re "you only need two files".

Two other points:

1) get in the habit of putting a small comment block at the top of each php file, eg
PHP Code:
<?php  
/* This module displays the home page. It contains no executable php other than an include of the standard band info */
?>
2) Relative pathnames, such as "textfiles/theband.txt" -- that assumes that the directory "textfiles" is in the same directory as the php file with the include -- if you have any confusion over this, post again.
__________________
Great music:
Please login or register to view this content. Registration is FREE



Please login or register to view this content. Registration is FREE

Last edited by Physicsguy; 05-14-2012 at 07:48 PM.. Reason: Fixed quote/code
PaulW is offline
Reply With Quote
View Public Profile
 
Old 05-14-2012, 07:48 PM Re: display content from external file into HTML
Average Talker

Posts: 23
Trades: 0
Thanks Paul so much for that explanation. It wasn't registering at first.

Now, do I use the "include" feature to include my css style sheet? Because the php file removed my styles. It also didn't use any carriage returns from my text file.

I guess I have a whole lot more to learn with this PHP stuff.
talytech is offline
Reply With Quote
View Public Profile
 
Old 05-14-2012, 07:51 PM Re: display content from external file into HTML
Physicsguy's Avatar
404 - Title not found

Posts: 1,060
Name: Scott Kaye
Location: Ontario
Trades: 0
Quote:
Originally Posted by talytech View Post
Now, do I use the "include" feature to include my css style sheet? Because the php file removed my styles. It also didn't use any carriage returns from my text file.
You don't to include the CSS with a PHP include. That would be the same as writing it out in <style> tags in the header each time. You can just use HTML's <link> to link the CSS:

HTML Code:
<link rel="stylesheet" href="css/style.css" type="text/css" />
However, you could do the same thing in PHP:

PHP Code:
<?php include("css/style.***"); ?> <- Assuming you have <style> tags around your CSS, or:
<?php echo '<style type="text/css">'.file_get_contents('css/style.css').'</style>';?> would also work.
__________________

Please login or register to view this content. Registration is FREE
Physicsguy is online now
Reply With Quote
View Public Profile Visit Physicsguy's homepage!
 
Old 05-15-2012, 12:14 PM Re: display content from external file into HTML
chrishirst's Avatar
Defies a Status

Posts: 43,957
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Quote:
also didn't use any carriage returns from my text file.
That's nothing to do with PHP. HTML does NOT use "carriage returns".
All "white space" which include line feeds and returns, is collapsed to a single space when parsed by the browser rendering engine.
To maintain plain text formatting (spaces, line feeds and carriage returns, tabs etc.) you need to put the text into
HTML Code:
<pre> (pre formatted text)</pre>
elements in the HTML document.
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Reply     « Reply to display content from external file into HTML
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.43603 seconds with 11 queries