how to call .txt file data in an html site

10 replies
HI

I have a big problem ..don't know how to solve it ...

I have html site which have almost 110 html pages ...

Problem is how can i call the data of .txt file in an html site ...

for ex:- i want to put the Google Analytics in all pages so i have to manually edit all pages ..what i want is i will add some code in this htmls pages then add the Google Analytics in .txt file ..and on run it will call the txt file data in that html site ...

Thing is i will edit once in all pages but then if i have to edit it i have the do it again all pages ..which is really lengthy process and time consuming ...

Or i just add additional data or new in that txt and it will update in all site ..in this option i have to just edit the one file the .txt file ...

This is possible is .php site ...but i don't have any idea in html how to do it ..

So do you guys know how to do this ...

please provide your suggestions ...

Regard
sumit
#call #data #file #html #html coding #html css web design #site #txt
  • Profile picture of the author Valdor Kiebach
    I think you might have to use some javascript and have the txt file contents loaded into a div in the HTML.

    Still going to be a long process.
    Might be easier to rename all files to .php and then use an include statement to show the adsense code but you would need to use a redirect in your .htaccess file like this:

    Code:
    RewriteEngine On
    RewriteRule ^(.*).html$ $1.php [L]
    So that your links to html pages will still work.
    {{ DiscussionBoard.errors[8407715].message }}
    • Profile picture of the author bapparabi
      Originally Posted by Valdor Kiebach View Post

      I think you might have to use some javascript and have the txt file contents loaded into a div in the HTML.
      Do you know that how to do it ...any reference will be great

      Still going to be a long process.
      Might be easier to rename all files to .php and then use an include statement to show the adsense code but you would need to use a redirect in your .htaccess file like this:

      Code:
      RewriteEngine On
      RewriteRule ^(.*).html$ $1.php [L]
      So that your links to html pages will still work.
      This will make big problem ..that all site ranking will be lost and all are live site with html extention ..as soon as its changed to .php all ranking will be lost An then it will be big blunder ....

      By the way thanks for you suggestion ..
      {{ DiscussionBoard.errors[8407728].message }}
  • Profile picture of the author Andrew H
    It's possible to run php inside .html files with a change to your htaccess file. This way you can just use php include. PHP: include - Manual

    Code:
    RemoveHandler .html .htm
    AddType application/x-httpd-php .php .html .htm
    Signature
    "You shouldn't come here and set yourself up as the resident wizard of oz."
    {{ DiscussionBoard.errors[8407762].message }}
  • Profile picture of the author Andrew H
    Hi thank you for suggestion but i am not high end tech guy and don't know php well ..so a better and simple example will help me ...
    This solution is simple as it's gonna get. Google what the php include() function is (it is exactly what you need). Basically it allows you to 'include' an external files content (ie: your code you want on every page) file into the current file. So in your main document you have something like:

    Code:
    file: index.html
    
    <h1>I am a pizza man</h1>
    <p>How much pizza do you eat?</p>
    <?php include('includes/pizza_amount.php'); ?>
    Code:
    file: includes/pizza_amount.php
    
    <?php
    echo '<p>5 pizzas!</p>';
    ?>
    End result that user sees:
    HTML Code:
    <h1>I am a pizza man</h1>
    <p>How much pizza do you eat?</p>
    <p>5 Pizzas!</p>
    So normally you can only run PHP inside a .php file, but the change to your .htaccess file will tell apache to run the PHP inside .html files (you might run into some problems if you have xml in your html files)

    Code:
    file: .htaccess
    
    #add the lines below to this file
    RemoveHandler .html .htm
    AddType application/x-httpd-php .php .html .htm
    Signature
    "You shouldn't come here and set yourself up as the resident wizard of oz."
    {{ DiscussionBoard.errors[8408068].message }}
    • Profile picture of the author bapparabi
      Originally Posted by Andrew H View Post

      This solution is simple as it's gonna get. Google what the php include() function is (it is exactly what you need). Basically it allows you to 'include' an external files content (ie: your code you want on every page) file into the current file. So in your main document you have something like:

      Code:
      file: index.html
      
      <h1>I am a pizza man</h1>
      <p>How much pizza do you eat?</p>
      <?php include('includes/pizza_amount.php'); ?>
      Code:
      file: includes/pizza_amount.php
      
      <?php
      echo '<p>5 pizzas!</p>';
      ?>
      End result that user sees:
      HTML Code:
      <h1>I am a pizza man</h1>
      <p>How much pizza do you eat?</p>
      <p>5 Pizzas!</p>
      So normally you can only run PHP inside a .php file, but the change to your .htaccess file will tell apache to run the PHP inside .html files (you might run into some problems if you have xml in your html files)

      Code:
      file: .htaccess
      
      #add the lines below to this file
      RemoveHandler .html .htm
      AddType application/x-httpd-php .php .html .htm
      great let me try this and see if this works or not in my html
      {{ DiscussionBoard.errors[8408111].message }}
  • Profile picture of the author RobinInTexas
    I would edit the htaccess as suggested by Andrew:
    Originally Posted by Andrew H View Post

    Code:
    file: .htaccess
    
    #add the lines below to this file
    RemoveHandler .html .htm
    AddType application/x-httpd-php .php .html .htm
    In any event you are going to have to edit each of the html files at least one time to insert the external information.

    It would be best to look at the pages and include all the common elements in one or several sections and the varied elements in separate sections.

    For Example
    • Header
    • Variable Content

    or
    • Header
    • Navigation
    • Content
    • Footer
    Signature

    Robin



    ...Even if you're on the right track, you'll get run over if you just set there.
    {{ DiscussionBoard.errors[8410517].message }}
  • Profile picture of the author Andrew H
    PHP is server side script so you shouldn't be able to see it in the html source.

    Did you make those changes to your .htaccess file? are you running a linux server?
    Signature
    "You shouldn't come here and set yourself up as the resident wizard of oz."
    {{ DiscussionBoard.errors[8410833].message }}

Trending Topics