Jump to content

[SOLVED] autoformat text...


ag3nt42

Recommended Posts

Hello again all,

 

I'm trying to setup a website where the owner can edit a .txt file without having to know any code..

and I want to be able to pull in that txt file to a php page and format it for them. based on certain text characteristics like.. if there is a period toss in a <br /> tag ect...

 

then directly display the newly formatted text on the webpage.. any ideas on how I could do that??

 

thankx alot,

 

ag3nt

Link to comment
Share on other sites

anyone feel free to jump in anytime here..

 

this is what I got so far..

 

<?php


$file = fopen("../Editable/welcome.txt","r");
$p=0;
while(! feof($file))
{
$z=fgetc($file);
if($z=='.')
{
	echo($z);
	echo('<br />');
	$p++;
}
else
{
	echo($z);
}

if($p==5)
{
echo("<br /><br />");
$p=0;
}
}
?>

this works pretty well. but its not perfect by far...

Link to comment
Share on other sites

this seems to work better then the last one

 

 

<?php

$file = fopen("../Editable/welcome.txt","r");
$p=0;
while(! feof($file))
{
$z=fgetc($file);

if($z=='%'){echo('<br />');}else{echo($z);}
if($z=='.'){$p++;}	
if($p==4){echo("<br /><br />");$p=0;}
}

?>

Link to comment
Share on other sites

I'm glad you found a solution. Good work.

 

 

lol thanks, I was hoping for some help figuring out how I can do it better tho...like right now

 

I can do either of those two ways... but if you put a period where a line doesn't end.. such as

 

P.O. Box    it will drop down a line at each period..

 

or for the second version.. I have to tell them to use a special character to go down a line.. which isn't kwl

 

seems like there should be alot easier way to do this.. like somehow preserve whitespace...

 

I tried using some CSS like white-space:pre; or normal; but neither works right.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.