itnifl
asked on
Reading and displaying tabs in PHP
I read and display a file this way:
<some code here>
while(!feof($file)) {
$number++;
$result .= "<tr><td width=\"11\">$number.</td> <td>". fgets($file) ."</td></tr>";
}
<some code here to finish the html table>
echo $result;
The problem is that when the table is displayed, tabs are not displayed. Thereby, the structure of the text, if tabs are used, is not correct.
<some code here>
while(!feof($file)) {
$number++;
$result .= "<tr><td width=\"11\">$number.</td>
}
<some code here to finish the html table>
echo $result;
The problem is that when the table is displayed, tabs are not displayed. Thereby, the structure of the text, if tabs are used, is not correct.
Hope this helps
$result ='<table "width=100%">';
while(!feof($file)) {
$number++;
$result .= "<tr><td width=\"11\">$number.</td><td>". fgets($file) ."</td></tr>";
}
$result ="</table>";
echo $result;
ASKER
Raods Roads: I need to display also the tabs. How would I do that?
shinug: you replaced my pseudocode(if you can call it that), with real code. That was not my intention :)
shinug: you replaced my pseudocode(if you can call it that), with real code. That was not my intention :)
Can you post a sample of that text file ?
Try either of these, as the text file need to be binary safe, b and t tags cane be used for such cases.
$handle = @fopen("test.txt", "rb");
$handle = fopen("test.txt", "rt");
Hope this helps
$handle = @fopen("test.txt", "rb");
$handle = fopen("test.txt", "rt");
Hope this helps
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Worked like a charm. Thanks!
FYI,
str_replace("\t", " ", $text);
wont pickup the \t in your text it .. :-)
str_replace("\t", " ", $text);
wont pickup the \t in your text it .. :-)
ASKER
The line I ended using was:
$result .= "<tr><td width=\"11\">$number.</td> <td>". str_replace("\t", " ", fgets($file)) ."</td></tr>";
It worked with me.
Why did you suspect that it wouldn't work? Just curious..
$result .= "<tr><td width=\"11\">$number.</td>
It worked with me.
Why did you suspect that it wouldn't work? Just curious..
"This is just a text."
will get [this] [is] [just] [a] [text] (without a tab after "is").