/    Sign up×
Community /Pin to ProfileBookmark

How do I use nl2br(); without breaking a line while I’m writing to a page?

Okay, this is basically what I’m doing:

(form sends post data with variable: text)

<?php
$text = $_POST[‘text’];
$text = nl2br($title);

$fp = fopen (‘textfile.txt’, ab);
flock ($fp, LOCK_EX);
fwrite ($fp, “$textn”);
flock ($fp, LOCK_UN);
fclose ($fp);

What happens is that the html breaks (br) start new lines and when I read it by making it an array, it registers the stuff after a break as a new line. How can I still use nl2br, but have it so it prints to the text document like:

line1|Printed text<br />more printed text<br /><br /><br />more text
line2|
line3|
line4|
line5|

instead of:

line1|Printed text<br />
line2|more printed text<br />
line3|<br />
line4|<br />
line5|more text

Any help would be really apreciated as I’ve resorted to using <input type=”text> instead of <textarea>

Edit: I’ve run int another problem too. If the text array value is something like:

“aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa”

it messes up my formating when I print it to a page. How can I cut it when it doesn’t fit in the specified area?

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@SpectreReturnsDec 03.2005 — How about just replacing n with <br />, because [b]nl2br()[/b] is meant to have this functionality.

Look into [url=http://php.net/wordwrap]wordwrap()[/url] to shorten things.
Copy linkTweet thisAlerts:
@urquanmasterauthorDec 06.2005 — Thanks. Forgot that n was the actual inputed representation of "break line". Wordwrap wasn't in the book I was using either. I'll have to get something more in-depth, like a complete reference list book on all php commands.
×

Success!

Help @urquanmaster 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 5.19,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

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

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...