/    Sign up×
Community /Pin to ProfileBookmark

How do I add a line break between these two lines when they get outputted?

<?php

$first=$_POST[‘first’];
$second=$_
POST[‘second’];

?>

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@shane_carrJun 09.2006 — I dont know exactly what you're asking for, as for there is no "output" statement in the code that you show. But,

[code=php]
<?php

$first = $_POST['first'];
$second = $_POST['second'];
echo "$first <br> $second"

?>
[/code]


will echo the variables onto the page with a line break.
Copy linkTweet thisAlerts:
@SheldonJun 09.2006 — I like this more but its the same thing really

[code=php]
<?php
$first = $_POST['first'];
$second = $_POST['second'];
echo("First:" . $first . "<br>Second:" . $second . "rn");

?>
[/code]


or you could make sure they are set
[code=php]
<?php
if(isset($_POST['first']))
{
$first = $_POST['first'];
}else{
$first = "Unset";
}

if(isset($_POST['second']))
{
$first = $_POST['second'];
}else{
$first = "Unset";
}

echo("First:" . $first . "<br>Second:" . $second . "rn");

?>
[/code]
Copy linkTweet thisAlerts:
@pcthugJun 09.2006 — [code=php]
<?php
$first - $_POST['first'];
$second = $_POST['second'];
// an escaped new line (n) for win/*nix
// an and escaped return (r) for mac
echo $first . 'nr' . $second;
?>[/code]
Copy linkTweet thisAlerts:
@cin_ruzauthorJun 09.2006 — ok. This is what I'm (hopelessly) trying to do.

Diagram:http://i26.photobucket.com/albums/c135/plunder112/diagram.gif

This is what I have so far:

[B]Page 1 - index.php[/B]

[code=php]<?php

$myFile = "file1.txt";
$fh = fopen($myFile, 'r');
$theData = fread($fh, filesize($myFile));
fclose($fh);
echo $theData;

?>

<html>
<body>

<form action="insert.php" method="post">
First Name: <input type="text" name="first">
<br>
Enter Sentence: <input name="second" type="text" value="" size="50" maxlength="50" />
<br/>
<input type="Submit" value="Enter">
</form>

</body>
</html>[/code]


[B]Page 2 - insert.php[/B]

[code=php]<?php
$first - $_POST['first'];
$second = $_POST['second'];
?>

<html>
<body>

<?

$ffile = "file1.txt";
$fh = fopen($ffile, 'w');

fwrite($fh, $count);
fwrite($fh, "n");
fwrite($fh,$first);
fwrite($fh,$second);

fclose($fh);

$myFile = "file.txt";
$fh = fopen($myFile, 'r');
$theData = fread($fh,1);
fclose($fh);
if ($theData == 0){

$count=1;
$ffile = "file.txt";
$fh = fopen($ffile, 'w');

fwrite($fh, $count);
fwrite($fh, "n");
fwrite($fh,$first);
fwrite($fh,$second);

fclose($fh);


}
else{
$ffile = "file.txt";
$fh = fopen($ffile, 'a');

fwrite($fh, $count);
fwrite($fh, "n");
fwrite($fh,$first);
fwrite($fh,$second);

fclose($fh);


}

$myFile = "file.txt";
$fh = fopen($myFile, 'r');
$theData = fread($fh, filesize($myFile));
fclose($fh);


?>

<br><hr>
<? echo $theData?>
<hr>

<form action="index.php">
<input type="Submit" title="back">
</form>

</body>
</html>[/code]


And then I have 2 text files.

[B]file.txt[/B]

and

[B]file1.txt[/B]


Can you help me out please?
×

Success!

Help @cin_ruz 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 6.17,
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: @nearjob,
tipped: article
amount: 1000 SATS,

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

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...