PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
maciek4
Forum Commoner
Posts: 29 Joined: Tue Apr 04, 2006 8:17 am
Post
by maciek4 » Wed Apr 12, 2006 9:58 am
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?
timvw
DevNet Master
Posts: 4897 Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium
Post
by timvw » Wed Apr 12, 2006 10:26 am
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")
maciek4
Forum Commoner
Posts: 29 Joined: Tue Apr 04, 2006 8:17 am
Post
by maciek4 » Thu Apr 13, 2006 5:25 am
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?
timvw
DevNet Master
Posts: 4897 Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium
Post
by timvw » Thu Apr 13, 2006 5:27 am
I wrote it correctly... But the syntax highlighter messed it up...
I hope it's clear that the two broken parts are:
maciek4
Forum Commoner
Posts: 29 Joined: Tue Apr 04, 2006 8:17 am
Post
by maciek4 » Thu Apr 13, 2006 5:44 am
ok it worked. How do I increment by 2
i+2?
maciek4
Forum Commoner
Posts: 29 Joined: Tue Apr 04, 2006 8:17 am
Post
by maciek4 » Thu Apr 13, 2006 8:22 am
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
maciek4
Forum Commoner
Posts: 29 Joined: Tue Apr 04, 2006 8:17 am
Post
by maciek4 » Thu Apr 13, 2006 8:49 am
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.
timvw
DevNet Master
Posts: 4897 Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium
Post
by timvw » Thu Apr 13, 2006 8:59 am
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?
maciek4
Forum Commoner
Posts: 29 Joined: Tue Apr 04, 2006 8:17 am
Post
by maciek4 » Thu Apr 13, 2006 9:10 am
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.
maciek4
Forum Commoner
Posts: 29 Joined: Tue Apr 04, 2006 8:17 am
Post
by maciek4 » Thu Apr 13, 2006 9:59 am
There is a problem with the loop not <br/>
timvw
DevNet Master
Posts: 4897 Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium
Post
by timvw » Thu Apr 13, 2006 11:55 am
Where is $lines coming from?
timvw
DevNet Master
Posts: 4897 Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium
Post
by timvw » Thu Apr 13, 2006 12:00 pm
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
}