Topic Closed
mabu
253 Posts
2.9K Downloads
3 Themes
8 Plugins

I am working at a plugin and want  to import  a textfile(table.md or table.txt)  into readfirst_x1.php and echo it in a div - but i get only errors.

echo " TEST "; gives of course TEST - but echo ' <span><font-family ...> gives an error about   font (after-interpreted though any string should have an output)

The textfile is in the same folder as readfirst_x1.php  ( i had this problem also in another context before)

[Admin_Link:Read_first_x1]
label = 'Please read details'
script = 'readfirst_x1.php'

I added in the php-file  :

 echo "<hr> <div> <br>";
 
$file = 'table.md';
$orig = file_get_contents($file);
$anoto = htmlentities($orig);

echo '<code>';
echo '<pre>';

echo $anoto;

echo '</pre>';
echo '</code>';
echo " End " ;   /*  this String appears !  */
 echo "</div>";

This gives only a broad gray line and END in the next line. Is there a special syntax for plugins ? Who knows a general solution ?

global $addonPathCode;
$plg = $addonPathCode;
$tab1 = '/table.md';
$file = $plg . $tab1 ;
if (file_exists($file))
{ echo "<br> The file $file exists"; }  /* it exists ! */
$f = fopen($file, "r") or exit("Unable to open file!");

while(!feof($f))
{   echo fgets($f)."<br />"; }  fclose($f);

gives no output

A 'solution' ala      https://stackoverflow.com/questions/4754387/php-how-do-i-display-the-contents-of-a-textfile-on-my-page?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa                 does not function either - nor readfile()

------------------------------------------------------------------------------------

P:S i found the solution : The 1st soultion give me to pages of empty screen, so i did not see that the echo file_get_contents( $file ); functions, whose code appaeared behind. ( Mc Murphy)

$f = fopen($file, "r") or exit("Unable to open file!");
// read file line by line until the end of file (feof) 
 if (file_exists($file)) {
 readfile( $file ); }---
 echo file_get_contents( $file );

Edited: 2 years ago#10944

juergen
1.5K Posts
53.7K Downloads
16 Plugins
design, web development & visual effects

IMO it largely depends on the content and origin of the text file.

To check a PHP variable you can (almost) always use sth. like …

msg('$myVariable = ' . pre($myVariable) );

which will output the variable's type and content in a message.
This will work with strings, numbers, booleans and arrays.

If the text file can be trusted in terms of security, you could also simply try

ob_start();

include('path/to/my_text.txt');

$myText = ob_get_clean();

echo '<pre>';
echo $myText;
echo '</pre>';

While developing, I'd also recommend to set the gpdebug constant to true in /gpconfig.php, which makes Typesetter quite verbose in terms of notices, warnings and errors.

Edited: 2 years ago#10946

juergen
1.5K Posts
53.7K Downloads
16 Plugins
design, web development & visual effects
If you don't want to use <pre> to keep linebreaks, you could also try nl2br.
Edited: 2 years ago#10947

Topic Closed

 

News

elFinder 2.1.50 in Upcoming Release
12/28/2019

A new release for Typesetter is in the works with a lot of improvements including the ... Read More

Typesetter 5.1
8/12/2017

Typesetter 5.1 is now available for download. 5.1 includes bug fixes, UI/UX improvements, ... Read More

More News

creisi productions

Dienstleistungen von creisi productions, Luzern (Schweiz): * Konzeption, Planung und Erstellung Ihres Internet-Auftritts * Betreuung und Aktualisierung/Pflege Ihrer Website * ...

Find out more about our Provider Spotlight

Log In

  Register