Jump to content

Need some help using line breaks.


Quick123

Recommended Posts

I've been making a program for school there is nothing wrong with the program itself except I don't know how to add line breaks inside a fwrite command.

 

I'll show the code below so I can explain a little easier.

 

The part in bold is where I need line breaks, any advice would be great.

 

<html>

<body>

 

<form action="IO1.PHP" method="post">

 

<p>

<label for="StrAccount"><b>Account:</b></label>

<input type="text" name="StrAccount" id="StrAccount" />

<input type="submit" name="submit"/>

</p>

 

<?PHP

 

/* Customers Information */

 

$Customer[0] = "Luiz Inácio Lula da Silva";

$Customer[1] = "J.T. Wang";

$Customer[2] = "Admiral Mike Mullen";

$Customer[3] = "Barack Obama";

$Customer[4] = "Ron Bloom";

 

$Phone[0] = "1234 5678";

$Phone[1] = "5678 1234";

$Phone[2] = "0000 1234";

$Phone[3] = "1234 0000";

$Phone[4] = "0000 0000";

 

$Title[0] = "The Shawshank Redemption";

$Title[1] = "The Godfather";

$Title[2] = "The Godfather: Part II";

$Title[3] = "Inception";

$Title[4] = "Sergio Leone's The Good, the Bad and the Ugly";

 

$Cost[0] = "$1.00";

$Cost[1] = "$2.00";

$Cost[2] = "$3.00";

$Cost[3] = "$4.00";

$Cost[4] = "$5.00";

 

$Return[0] = "01/01/2010";

$Return[1] = "01/02/2010";

$Return[2] = "01/03/2010";

$Return[3] = "01/04/2010";

$Return[4] = "01/05/2010";

 

if (isset($_POST["submit"]))

{

$Text = fopen ("Customers.txt", 'w');

$StrAccount = $_POST["StrAccount"];

 

if ($StrAccount == $Customer[0])

 

{

echo "<p><b>$Customer[0], $Phone[0], $Title[0], $Cost[0], $Return[0]</b></p>";

fwrite ($Text, $Customer[0]);

fwrite ($Text, $Phone[0]);

fwrite ($Text, $Title[0]);

fwrite ($Text, $Cost[0]);

fwrite ($Text, $Return[0]);

}

 

elseif ($StrAccount == $Customer[1])

 

{

echo "<p><b>$Customer[1], $Phone[1], $Title[1], $Cost[1], $Return[1]</b></p>";

fwrite ($Text, $Customer[1]);

fwrite ($Text, $Phone[1]);

fwrite ($Text, $Title[1]);

fwrite ($Text, $Cost[1]);

fwrite ($Text, $Return[1]);

}

 

elseif ($StrAccount == $Customer[2])

 

{

echo "<p><b>$Customer[2], $Phone[2], $Title[2], $Cost[2], $Return[2]</b></p>";

fwrite ($Text, $Customer[2]);

fwrite ($Text, $Phone[2]);

fwrite ($Text, $Title[2]);

fwrite ($Text, $Cost[2]);

fwrite ($Text, $Return[2]);

}

 

elseif ($StrAccount == $Customer[3])

 

{

echo "<p><b>$Customer[3], $Phone[3], $Title[3], $Cost[3], $Return[3]</b></p>";

fwrite ($Text, $Customer[3]);

fwrite ($Text, $Phone[3]);

fwrite ($Text, $Title[3]);

fwrite ($Text, $Cost[3]);

fwrite ($Text, $Return[3]);

}

 

elseif ($StrAccount == $Customer[4])

 

{

echo "<p><b>$Customer[4], $Phone[4], $Title[4], $Cost[4], $Return[4]</b></p>";

fwrite ($Text, $Customer[4]);

fwrite ($Text, $Phone[4]);

fwrite ($Text, $Title[4]);

fwrite ($Text, $Cost[4]);

fwrite ($Text, $Return[4]);

}

 

else

 

{

echo "<p><b>This Account Does Not Exist.</b></p>";

}

}

 

?>

 

</body>

</html>

 

Link to comment
Share on other sites

"\n" is new line

BTW you could shorten your code by using a variable for the Customer/phone/etc number.

 

ie

 

$what_cust_num = 1;
echo "<p><b>$Customer[$what_cust_num], $Phone[$what_cust_num ], $Title[$what_cust_num ], $Cost[$what_cust_num ], $Return[$what_cust_num ]</b></p>";
$save_string = $Customer[$what_cust_num] . "|" . $Phone[$what_cust_num] . "|" . $Title[$what_cust_num] . "|" . $Cost[$what_cust_num] . "|" . $Return[$what_cust_num] . "\n";

fwrite ($Text, $save_string);

would put all the info into one line, with pipe "|" as separator and a new line at the end

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.