Jump to content

how to parse an external txt file


thetooth

Recommended Posts

hi i am using a light weight bbcode parser called http://www.webtech101.com/PHP/simple-bb-code and i've ran into a big prob. i writ a simple file editor so i can type in bbcode and then the parser takes care of it

 

but the prob is i don't know how i should be calling in the text file so the parser can use it. I've tried include and fopen but both don't work because $t must equal 'the raw bbcode' so using some like $t = include('file.txt'); will ether give me an error or will call the file name and script instance rather then the text in the file. so heres my script below please help me!

 

<?php
//////////////////////////////////////////////////////////////////////////////////
//Display pharsed text////////////////////////////////////////////////////////////
//error_reporting(~E_ALL);
$t = fopen("file.txt","r");
require_once('engine.php');
$bb = new BB_Code();
$res = $bb->parse($t);
echo "<div style='border:1px solid #CCCCCC'>$res</div>";
//////////////////////////////////////////////////////////////////////////////////
//Now lets make a form to edit the text :)////////////////////////////////////////
if($_POST['Submit']){
$open = fopen("file.txt","w+");
$text = $_POST['update'];
fwrite($open, $text);
fclose($open);
echo "File updated.<br />";
echo "File:<br />";
$file = file("file.txt");
foreach($file as $text) {
echo $text."<br />";
}
}else{
$file = file("file.txt");
echo "<form action=\"".$PHP_SELF."\" method=\"post\">";
echo "<textarea Name=\"update\" cols=\"50\" rows=\"10\">";
foreach($file as $text) {
echo $text;
}
echo "</textarea>";
echo "<input name=\"Submit\" type=\"submit\" value=\"Update\" />\n
</form>";
}
?>

Link to comment
https://forums.phpfreaks.com/topic/121818-how-to-parse-an-external-txt-file/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.