/    Sign up×
Community /Pin to ProfileBookmark

Read data from a file and justify the text

Any suggestion Please…

I have about ten paragraphs of text that is inside the file is calls output.txt and I want the file named table.php to read this file (output.txt) and justify all the text and output to the screen, but the problem is that all of the text in each paragraph got to be in one long line, otherwise, it won’t work at all. You can use these text lines to test.

To make it clear that all of the above text in each paragraph got to be in one line, in order to make it work (justify the text).

Thanks very much.

——–This is called [table.php]————
<HTML>
<HEAD>
<TITLE></TITLE>
<STYLE>
<!–
.button_rgb0001_0001
{

BORDER-RIGHT: #000000 1px solid;
PADDING-RIGHT: 10px;
BORDER-TOP: #4b4d5b 1px solid;
PADDING-LEFT: 1px;
FONT-SIZE: 8pt;
BACKGROUND: #292831;
PADDING-BOTTOM: 1px;
BORDER-LEFT: #4b4d5b 1px solid;
COLOR: #7e7e7e;
PADDING-TOP: 10px;
BORDER-BOTTOM: #000000 1px solid;
FONT-FAMILY: “MS Sans Serif”, Verdana, Helvetica, Arial, sans-serif

}

p.tp-tble10-0002 {FONT-WEIGHT: normal; FONT-SIZE: 10pt; TEXT-ALIGN: justify; COLOR: #aaaaaa; FONT-STYLE: normal; FONT-FAMILY: “Times New Roman”, “MS Sans Serif”, Arial, sans-serif}

//–>
</STYLE>
</HEAD>

<BODY bgcolor=”#293831″>

<table CLASS=button_rgb0001_0001 Align=”CENTER” cellspacing=”10″ style=”border-collapse: collapse” width=”30%”>
<tr>
<td>

<?

// the following statement opens the files called output.txt
// and reads each line of the file into an array called $readfile

// Each line will be accessed by it’s position in the array
// $readfile[0] would be the first line because the array begins at 0
// rather than 1

//———————————————-
$readfile = file(“output.txt”);

// Create a loop that will read all elements of the array and print out
// each field of the tab-delimited text file

for ($k=0; $k<=count($readfile)-1; $k++)
{
$fields = split(“t”,$readfile[$k]);
print(“<font color=”#888888″><p style=”text-align:justify”>$fields[0]</font>”);
}

//———————————————–
$readfile = file(“output.txt”);
print(“<HR>”);
for ($k=0; $k<=count($readfile)-1; $k++)
{
$fields = split(“t”,$readfile[$k]);
print(“<p class=”tp-tble10-0002″>$fields[0]</p>”);
}
$readfile = file(“output.txt”);
print(“<HR>”);
for ($k=0; $k<=count($readfile)-1; $k++)
{
$fields = split(“t”,$readfile[$k]);
print(“<p class=”tp-tble10-0002″>$fields[0]</p>”);
}
</TD>
</TR>

</TABLE>
—————————————

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@ShrineDesignsFeb 14.2005 — &lt;p style="text-align: justify;"&gt;...&lt;/p&gt;
Copy linkTweet thisAlerts:
@cunocauthorFeb 14.2005 — I did this way and your advise, but still doesn't work, it only work when all the text in a paragraph got to be in one long line.

p.tp-tble10-0002 {FONT-WEIGHT: normal; FONT-SIZE: 10pt; TEXT-ALIGN: justify; COLOR: #aaaaaa; FONT-STYLE: normal; FONT-FAMILY: "Times New Roman", "MS Sans Serif", Arial, sans-serif}
Copy linkTweet thisAlerts:
@NogDogFeb 14.2005 — If each line from the .txt file is just part of what you want to be a justified paragraph, then it would be something like:
[code=php]
$text = file("myfile.txt");
echo "<p style='text-align: jutify'>";
foreach($text as $line)
{
echo line;
}
echo "</p>n";
[/code]

Even simpler:
[code=php]
echo "<p style='text-align: justify'>".readfile("myfile.txt")."</p>n";
[/code]
Copy linkTweet thisAlerts:
@cunocauthorFeb 14.2005 — I tried, but it not justify. It only work when the whole text in a paragraph is in one long line of text, it means that if I have a long paragraph of text then the text need to be in one line otherwise it doesn't work.

Thankss
×

Success!

Help @cunoc 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 5.20,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

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

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...