Page 1 of 1

handling files

Posted: Wed Apr 12, 2006 9:58 am
by maciek4
I want to write the content of 2 fields to a file and then display it on another page in seperate lines

Code: Select all

$data = trim($name."\n".$desc."\n");
fwrite($fp, $dane);
and the result is that its in 1 line. How to make it display in 2 lines?

Posted: Wed Apr 12, 2006 10:26 am
by timvw
Why do you add the last \n if you trim the string? (and thus remove that last \n).

Code: Select all

$line = trim($name) . "\n" . trim($desc) . "\n";
Offcourse, when you're on windows you'll need \r\n instead. (And why're going to display this in html, you'll need nl2br if you want the same "layout")

Posted: Thu Apr 13, 2006 5:25 am
by maciek4
timvw wrote:Why do you add the last \n if you trim the string? (and thus remove that last \n).

Code: Select all

$line = trim($name) . "\n" . trim($desc) . "\n";
Offcourse, when you're on windows you'll need \r\n instead. (And why're going to display this in html, you'll need nl2br if you want the same "layout")
Something wrong with this :#

Code: Select all

$line = trim($name) . "\n" . trim($desc) . "\n";
Can you write it correctly?

Posted: Thu Apr 13, 2006 5:27 am
by timvw
I wrote it correctly... But the syntax highlighter messed it up...

I hope it's clear that the two broken parts are:

Code: Select all

"\n"

Posted: Thu Apr 13, 2006 5:44 am
by maciek4
ok it worked. How do I increment by 2

i+2?

Posted: Thu Apr 13, 2006 8:22 am
by maciek4
Ok it worked.


I want afret every 2 lines to add link

so 2 lines of text then link below

another 2 lines of text the same link below etc

Posted: Thu Apr 13, 2006 8:49 am
by maciek4

Code: Select all

for ($i=1;$i<count($lines);$i+=2)  
{
   echo nl2br($lines[$i]) . "<br /><br />\n";
   for ($i=2;$i<count($lines);$i+=2)
   {
   echo nl2br($lines[$i]) . "<br /><br />\n";
   echo '<a href="'.$_SERVER['REQUEST_URI'].'">Delete</a>' ;
   echo '<a href="commit.php?edit" name="edit">edit</a>'. "<br /><br />\n";
 }
 }


almost works.

I want it to look like this:

Product A
Description A
links

Product B
Description B
links

Product C
Descritpion C
links

etc

It gives me

Product A
Description A

links

Description B

links

Description C

links

etc

so I'm missig Product names from 3 line on.

Posted: Thu Apr 13, 2006 8:59 am
by timvw
maciek4 wrote:

Code: Select all

echo nl2br($lines[$i]) . "<br /><br />\n";
would output:

the product<br/>
description<br/>
<br/>
<br/>

See what you need to change?

Posted: Thu Apr 13, 2006 9:10 am
by maciek4
timvw wrote:
maciek4 wrote:

Code: Select all

echo nl2br($lines[$i]) . "<br /><br />\n";
would output:

the product<br/>
description<br/>
<br/>
<br/>

See what you need to change?
Nope. I still cant get Product names.

Posted: Thu Apr 13, 2006 9:59 am
by maciek4
There is a problem with the loop not <br/>

Posted: Thu Apr 13, 2006 11:55 am
by timvw
Where is $lines coming from?

Posted: Thu Apr 13, 2006 12:00 pm
by timvw
Your two loops both modify $i.

Code: Select all

for($i = 0; $i < count($lines); $i += 2) {
  //output $lines[$i] -> product
  // output $lines[$i+1] -> description
  // output link
}