collapse

* Simple Portal Archived Forum

This is an Archive Forum.

The content in this forum may be out-of-date or have been superseded by newer information, and links in forum pages to other sites may not work.
This forum contains archives for future reference.

Visit our thread at Simple Machines Forum for current support.

SMF 2.1 users: EhPortal is a ported version of Simple Portal specifically designed for the SMF 2.1 branch.
Please visit web-develop.ca to download EhPortal and for its support.

* User Info

 
 
Welcome, Guest. Please login or register.

* Who's Online

  • Dot Guests: 285
  • Dot Hidden: 0
  • Dot Users: 0

There aren't any users online.

* Shoutbox

Refresh History
  • Shoutbox is not for support!
  • {OCS}MasterSeal: Yup, Still adore SP
    April 21, 2019, 07:08:06 PM
  • {OCS}MasterSeal: STILL love SP :)
    November 24, 2018, 05:05:50 AM
  • ♦ Ninja ZX-10RR ♦: <3 aegersz
    September 13, 2018, 03:36:09 PM
  • aegersz: I STILL <3 LOVE SimplePortal
    September 13, 2018, 07:11:39 AM
  • aegersz: o LOVE you guys - Simple Portal rocks !
    May 09, 2018, 05:18:59 AM
  • Chen Zhen: our apologies for the site being down.. please read server issues topic
    March 22, 2018, 05:32:38 AM
  • {OCS}MasterSeal: LOL PLEASE forget I just posted that. I found the answer in my own dang post back in 2015. lol sorry!
    July 04, 2017, 10:47:55 PM
  • {OCS}MasterSeal: I know this SB isnt' for support, but I just have a general question. Who would I contact to find out where SP stores its block info? Is it DB driven or files? I searched the site but came up with nothing. probably my fault any insight is appreciated.
    July 04, 2017, 10:43:36 PM
  • ♦ Ninja ZX-10RR ♦: Excuse me but what does Simpleportal have to deal with that?
    February 05, 2017, 08:21:14 PM
  • WhiteEagle: of course IMHO that site appears to be dead :(
    February 04, 2017, 01:08:05 PM
  • WhiteEagle: If I can get that, then I'll use it for that site...
    February 04, 2017, 01:07:35 PM
  • WhiteEagle: decided to not use SMF for any projects, unless I can get a copy of the premium version of the fanfiction archive plugin
    February 04, 2017, 01:06:54 PM
  • expertdecisions: cloudflare
    January 28, 2017, 08:01:47 AM
  • aegersz: SM release 2.0.13 !
    January 12, 2017, 06:00:13 AM
  • raffo: Tks Emanuele, even if I didn't understand the fix :D
    November 07, 2016, 02:01:20 AM
  • emanuele: [link]
    November 01, 2016, 12:43:50 PM
  • emanuele: raffo: the English support board is a good place. ;)
    November 01, 2016, 12:43:38 PM
  • raffo: Where can I find the fix for the shoutbox?
    November 01, 2016, 05:06:09 AM
  • {OCS}MasterSeal: To the SP team, I make a point to come here and thank you as much as possible for your work.  so again, THANK YOU!
    October 28, 2016, 10:38:05 AM
  • emanuele: That's indeed funny, the limit is present only in the patch and not the full install.
    October 22, 2016, 06:14:58 PM

* Recent Posts

Adding Forums Button to Nav bar by jirapon
[August 01, 2019, 09:07:12 AM]


Re: Board Icons by ♦ Ninja ZX-10RR ♦
[July 30, 2019, 04:03:41 PM]


MOVED: Czech translation???? by ♦ Ninja ZX-10RR ♦
[July 30, 2019, 03:04:51 PM]


Board Icons by jirapon
[July 30, 2019, 07:28:44 AM]


Re: Thankyou Simpleportal, by ♦ Ninja ZX-10RR ♦
[July 29, 2019, 09:41:29 AM]

If you're interested in helping other members with support requests, consider joining the Community Support Helpers group.

Author Topic: Display TXT file content in a block?  (Read 4838 times)

0 Members and 1 Guest are viewing this topic.

Offline tfs

  • Jr. Member
  • **
  • Posts: 64
Display TXT file content in a block?
« on: September 11, 2011, 06:21:56 PM »
I've been trying to figure out a way to display the content of a TXT file in a block, but have been stymied so far.

I want to allow someone (100% trustworthy) to display information on a forum.  They want to do so via a TXT file, which I can then use an FTP script on their machine to put wherever it needs to go on the forum.  When they want to change the content they merely publish a new TXT file.  So I thought I'd display a PHP or HTML block that pulls the content of that TXT file.

Has anyone done this before?  It should be simple, and I've tried a few variations of scripts that are all over the net, to no avail thus far.

Offline ccbtimewiz

  • Hero Member
  • *****
  • Posts: 2185
  • Gender: Male
  • $("div.content:dd").hide();
  • SMF Version: None
  • SP Version: None
  • Elkarte Version: None
  • EhPortal Version: None
Re: Display TXT file content in a block?
« Reply #1 on: September 11, 2011, 09:45:35 PM »
For SMF 2.0:

Code: [Select]
<?php

global $smcFunc;

// Your file, should be defined as a txt as you requested
$file '/path/to/the/file/on/the/system/file.txt';

// Get the information from the file and then clean it
$output file_get_contents($file);
$output $smcFunc['htmlspecialchars'](trim($output), ENT_QUOTES);

echo 
$output;

?>
« Last Edit: September 11, 2011, 09:54:20 PM by ccbtimewiz »

Offline tfs

  • Jr. Member
  • **
  • Posts: 64
Re: Display TXT file content in a block?
« Reply #2 on: September 12, 2011, 12:24:14 AM »
Thanks, that finally got it.  I found a tip on another site to maintain the formatting within the TXT file by using "pre" tag, though then it's displayed in a fixed-width font.

Code: [Select]
<?php
global $smcFunc;
// Your file, should be defined as a txt as you requested
$file '/homepages/x/helpdesk/license.txt';

// Get the information from the file and then clean it
$output file_get_contents($file);
$output $smcFunc['htmlspecialchars'](trim($output), ENT_QUOTES);
echo 
'<pre>';
echo 
$output;
echo 
'</pre>';
?>

Offline ccbtimewiz

  • Hero Member
  • *****
  • Posts: 2185
  • Gender: Male
  • $("div.content:dd").hide();
  • SMF Version: None
  • SP Version: None
  • Elkarte Version: None
  • EhPortal Version: None
Re: Display TXT file content in a block?
« Reply #3 on: September 12, 2011, 02:16:24 AM »
If you want to keep the format of the text file, you can use nl2br()

Code: [Select]
<?php
global $smcFunc;
// Your file, should be defined as a txt as you requested
$file '/homepages/x/helpdesk/license.txt';

// Get the information from the file and then clean it
$output file_get_contents($file);
$output $smcFunc['htmlspecialchars'](trim($output), ENT_QUOTES);
$output nl2br($output);

echo 
$output;

?>
« Last Edit: September 12, 2011, 02:52:35 AM by ccbtimewiz »

Offline tfs

  • Jr. Member
  • **
  • Posts: 64
Re: Display TXT file content in a block?
« Reply #4 on: September 12, 2011, 02:59:36 PM »
Nice... that works.  Now for the hard part.  :)  What I've been ultimately trying to do is to incorporate this PHP code that displays a TXT file into an existing HTML block, so that it displays inside of a specific grid of a table.  This is the raw HTML I'm using.

Code: [Select]
<span class="upperframe"><span></span></span>
<div class="roundframe"><br>
<div style="text-align: center;"><big>If
your issue is critical, please call the office after filing a ticket
(555)555-1212 and ask for Technical Support. </big><br>
</div>
<br>
<table style="text-align: left; margin-left: auto; margin-right: auto; width: 95%;" cellpadding="6" cellspacing="6">
  <tbody>
    <tr>

      <td style="border: 1px solid rgb(94, 123, 182); background-color: rgb(208, 220, 234); vertical-align: top; width: 24%;"><span style="font-weight: bold;">REMINDER: </span>the
first Thursday of
each month at 10am CT and repeating at 2pm CT, SD2 hosts webinar
discussion/training sessions on hot topics desired by our clients.
Webinar connection instructions are e-mailed to clients two days prior
to each meeting (also posted on sd2.patsong.com). We
hope you can join us! <em></em> </td>
      <td style="border: 1px solid rgb(88, 13, 74); background-color: rgb(218, 195, 223); vertical-align: top; width: 24%;"><strong></strong><font><span style="font-weight: bold;"></span></font><span style="font-weight: bold;">Thursday 7/7, is our First Thursday
TechFest (User Forum) for July.&nbsp; </span>The current schedules
calls for the subject to be "Mapping Software" for people with no sense
of direction.<br>
      <br>
      </td>
    </tr>
  </tbody>

</table>
<br>
<table style="text-align: left; margin-left: auto; margin-right: auto; width: 95%;" cellpadding="6" cellspacing="6">
  <tbody>
    <tr>
      <td style="border: 1px solid rgb(88, 13, 74); background-color: rgb(218, 195, 223); vertical-align: top; width: 24%;"><span style="font-weight: bold;"></span><font><span style="font-weight: bold;">Check out our main page for important
random filler material!</span></font><br>
      <em></em> </td>
      <td style="border: 1px solid rgb(94, 123, 182); background-color: rgb(208, 220, 234); vertical-align: top; width: 24%;"><span style="font-weight: bold;">SD2 Patsong, Inc. (SD2)</span><br>
4444 N. Hello Ave., #224<br>

Los Angeles, CA&nbsp; 90503<br>
(555)555-1212 - Voice<br>
(888)555-1212 - Toll Free<br>
(555)555-1211 - Fax<br>
      <br>
      </td>
    </tr>
  </tbody>

</table>
<br>
<table style="text-align: left; margin-left: auto; margin-right: auto; width: 95%;" cellpadding="6" cellspacing="6">
  <tbody>
    <tr>
      <td style="border: 1px solid rgb(94, 123, 182); background-color: rgb(208, 220, 234); vertical-align: top; width: 24%;"><span style="font-weight: bold;">REMINDER: </span>the
first Thursday of
each month at 10am CT and repeating at 2pm CT, SD2 hosts webinar
discussion/training sessions on hot topics desired by our clients.
Webinar connection instructions are e-mailed to clients two days prior
to each meeting (also posted on sd2.patsong.com). We
hope you can join us! <em></em> </td>
      <td style="border: 1px solid rgb(88, 13, 74); background-color: rgb(218, 195, 223); vertical-align: top; width: 24%;"><strong></strong><font><span style="font-weight: bold;"></span></font><span style="font-weight: bold;"></span>
<?php
global $smcFunc;
// Your file, should be defined as a txt as you requested
$file '/homepages/x/helpdesk/license.txt';

// Get the information from the file and then clean it
$output file_get_contents($file);
$output $smcFunc['htmlspecialchars'](trim($output), ENT_QUOTES);
$output nl2br($output);

echo 
$output;
?>
<br>
      <br>

      </td>
    </tr>
  </tbody>
</table>
<br>
<br>
</div>

<span class="lowerframe"><span></span></span>

But I have been unable to use PHP inside of that table to display a TXT file.  The PHP is embedded within the bottom right grid of the table, and yet nothing appears.  But if I display the PHP via a PHP block, the text appears.

Offline ccbtimewiz

  • Hero Member
  • *****
  • Posts: 2185
  • Gender: Male
  • $("div.content:dd").hide();
  • SMF Version: None
  • SP Version: None
  • Elkarte Version: None
  • EhPortal Version: None
Re: Display TXT file content in a block?
« Reply #5 on: September 12, 2011, 03:20:00 PM »
Make a new PHP block, and put this as the content:

Code: [Select]
<?php

echo '
<span class="upperframe"><span></span></span>
<div class="roundframe"><br>
<div style="text-align: center;"><big>If
your issue is critical, please call the office after filing a ticket
(555)555-1212 and ask for Technical Support. </big><br>
</div>
<br>
<table style="text-align: left; margin-left: auto; margin-right: auto; width: 95%;" cellpadding="6" cellspacing="6">
  <tbody>
    <tr>

      <td style="border: 1px solid rgb(94, 123, 182); background-color: rgb(208, 220, 234); vertical-align: top; width: 24%;"><span style="font-weight: bold;">REMINDER: </span>the
first Thursday of
each month at 10am CT and repeating at 2pm CT, SD2 hosts webinar
discussion/training sessions on hot topics desired by our clients.
Webinar connection instructions are e-mailed to clients two days prior
to each meeting (also posted on sd2.patsong.com). We
hope you can join us! <em></em> </td>
      <td style="border: 1px solid rgb(88, 13, 74); background-color: rgb(218, 195, 223); vertical-align: top; width: 24%;"><strong></strong><font><span style="font-weight: bold;"></span></font><span style="font-weight: bold;">Thursday 7/7, is our First Thursday
TechFest (User Forum) for July.&nbsp; </span>The current schedules
calls for the subject to be "Mapping Software" for people with no sense
of direction.<br>
      <br>
      </td>
    </tr>
  </tbody>

</table>
<br>
<table style="text-align: left; margin-left: auto; margin-right: auto; width: 95%;" cellpadding="6" cellspacing="6">
  <tbody>
    <tr>
      <td style="border: 1px solid rgb(88, 13, 74); background-color: rgb(218, 195, 223); vertical-align: top; width: 24%;"><span style="font-weight: bold;"></span><font><span style="font-weight: bold;">Check out our main page for important
random filler material!</span></font><br>
      <em></em> </td>
      <td style="border: 1px solid rgb(94, 123, 182); background-color: rgb(208, 220, 234); vertical-align: top; width: 24%;"><span style="font-weight: bold;">SD2 Patsong, Inc. (SD2)</span><br>
4444 N. Hello Ave., #224<br>

Los Angeles, CA&nbsp; 90503<br>
(555)555-1212 - Voice<br>
(888)555-1212 - Toll Free<br>
(555)555-1211 - Fax<br>
      <br>
      </td>
    </tr>
  </tbody>

</table>
<br>
<table style="text-align: left; margin-left: auto; margin-right: auto; width: 95%;" cellpadding="6" cellspacing="6">
  <tbody>
    <tr>
      <td style="border: 1px solid rgb(94, 123, 182); background-color: rgb(208, 220, 234); vertical-align: top; width: 24%;"><span style="font-weight: bold;">REMINDER: </span>the
first Thursday of
each month at 10am CT and repeating at 2pm CT, SD2 hosts webinar
discussion/training sessions on hot topics desired by our clients.
Webinar connection instructions are e-mailed to clients two days prior
to each meeting (also posted on sd2.patsong.com). We
hope you can join us! <em></em> </td>
      <td style="border: 1px solid rgb(88, 13, 74); background-color: rgb(218, 195, 223); vertical-align: top; width: 24%;"><strong></strong><font><span style="font-weight: bold;"></span></font><span style="font-weight: bold;"></span>'
;

global 
$smcFunc;
// Your file, should be defined as a txt as you requested
$file '/homepages/x/helpdesk/license.txt';

// Get the information from the file and then clean it
$output file_get_contents($file);
$output $smcFunc['htmlspecialchars'](trim($output), ENT_QUOTES);
$output nl2br($output);

echo 
$output;

echo 
'<br>
      <br>

      </td>
    </tr>
  </tbody>
</table>
<br>
<br>
</div>

<span class="lowerframe"><span></span></span>'
;

?>

Offline tfs

  • Jr. Member
  • **
  • Posts: 64
Re: Display TXT file content in a block?
« Reply #6 on: September 12, 2011, 09:36:39 PM »
I'm truly impressed with your prowess and generosity.  Thank you, thank you, and thank you again!!!  This is actually something I can really use.  :)

I hope I can return the favor some day!

Now... I'm off to study just what's happening in that PHP, and to learn to tweak it here and there.