/    Sign up×
Community /Pin to ProfileBookmark

Is it possible to merge an html file with a txt file?

Here’s my quandry….

I want to have the obits that I have typed up (in txt form) available to viewing. I want to be able to take an html page and insert the txt file of a deceased to output into an html file displaying my webpage template and the obit of the deceased.

I believe it can be done with php but I am not very knowledgeable concerning php syntax. I’m thinking php include?

Any and all suggestions and help would be greatly appreciated.

Lynn

to post a comment
PHP

8 Comments(s)

Copy linkTweet thisAlerts:
@bokehJul 27.2005 — You need to ensure the text file does not contain any html tag as these could mess up your formating or worse. Try this:[code=php]<?php nl2br(striptags(include('file.txt'))); ?>[/code]
Copy linkTweet thisAlerts:
@KandlelightauthorJul 27.2005 — I got this error message

Fatal error: Call to undefined function: striptags() in /Obitpage.php on line 56

Oh, and the txt files are straight txt files. No html is in them.
Copy linkTweet thisAlerts:
@NogDogJul 28.2005 — How are these text files formatted? If each is a single paragraph, then all you need is:
[code=php]
<p>
<?php include ("textfile.txt"); ?>
</p>
[/code]

If there is more than one paragraph, then we need to know how those paragraphs are delineated in the text file so we can figure out how to parse them and convert them into appropriate HTML tags.
Copy linkTweet thisAlerts:
@KandlelightauthorJul 28.2005 — Ok, the text file does have more than one paragraph. I just put normal returns in the file for the paragraphs. You can view one of the text files here: http://www.kandlelight.net/obits/ALLENEffie.txt

When I changed the php code in my html to the above I had these errors return:

Warning: main(../obits/ALLENEffie.txt): failed to open stream: No such file or directory in i/public_html/Obitpage.php on line 56

Warning: main(): Failed opening '../obits/ALLENEffie.txt' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /public_html/Obitpage.php on line 56

Thank you so much for all of the assistance you are giving me. I know it's hard to get across what I'm trying to explain.
Copy linkTweet thisAlerts:
@griff777Jul 28.2005 — Here's my quandry....

I want to have the obits that I have typed up (in txt form) available to viewing. I want to be able to take an html page and insert the txt file of a deceased to output into an html file displaying my webpage template and the obit of the deceased.

I believe it can be done with php but I am not very knowledgeable concerning php syntax. I'm thinking php include?

Any and all suggestions and help would be greatly appreciated.

Lynn[/QUOTE]


The <?php include("somefile.txt"); ?> should work ticatee boo. I've used it with html in the text file, and it didn't seem to belly ache at all. Experiment, after all, the computer is probably the most wonderful sand box to play in of all modern toys.

Hope that helps.
Copy linkTweet thisAlerts:
@NogDogJul 28.2005 — [code=php]
<?php
# read file into an array:
if($text = file("http://www.kandlelight.net/obits/ALLENEffie.txt"))
{
foreach($text as $line) # loop through each line
{
$line = trim($line); # get rid of leading/trailing spaces and newlines
if(!empty($line)) # if something there, output a paragraph
{
echo "<p>$line</p>n";
}
}
}
?>
[/code]

NOTE: The argument to the file() function can just be the relative path/filename if on the same server.
Copy linkTweet thisAlerts:
@BeachSideJul 28.2005 — I would still stick to the simpler nl2br this way they can just hit enter(return) twice and it would format it properly only I would use the proper function Bokeh ?
[code=php]
<?php nl2br(strip_tags(include('file.txt'))); ?> // You forgot the underscore :)
[/code]


This is not to say that NogDog's solution is not fantastic I just think that it is a bit more complex than what one might need

BTW offtopic here but wtf is... "ticatee boo" griff777? :eek:
Copy linkTweet thisAlerts:
@NogDogJul 28.2005 — In my opinion, the <br> tag is a kludge that results in poor, inflexible HTML markup and styling. Using <p>...</p> tags gives us proper semantic markup and makes styling much easier. I can put everything within a <div class="obit">...</div>, then define in my CSS how I want the paragraphs to appear with a ".obit p" identifier. Using <br> tags, you'll just have one paragraph with no way to control paragraph spacing, first-line indents, etc.
×

Success!

Help @Kandlelight spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.15,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...