/    Sign up×
Community /Pin to ProfileBookmark

Replacing n with <br>

Hi ?

I wrote a small text in a file called text.txt. The text reads something like this:

Hello there!

How are you?
Im fine!

But when I print this file on the screen i see the text placed in one line like this:

Hello there!How are you?Im fine!

So I was thinking maybe I could replace all the n in the text file with a <br> ?
How can I do this? Or is there a better solusuoin?

THX!

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@Khalid_AliAug 29.2003 — I am not very well versed in PHP how ever,Here is what I can sugges.

When a fileis read the file ointer already knows where is the linbreak in the file,so you don't have to worry about that.just read the file using

fgets

and after every new line append the line with <br/>

I am sure you are already familiar with file system functions...

if not then visit resource.

http://www.php.net/manual/en/ref.filesystem.php
Copy linkTweet thisAlerts:
@Kr_ZAug 29.2003 — [code=php]
$string = ereg_replace("n", "<br>", $string);
[/code]
Copy linkTweet thisAlerts:
@pyroAug 29.2003 — Just use [URL=http://www.php.net/nl2br]nl2br()[/URL]...
Copy linkTweet thisAlerts:
@deepauthorAug 29.2003 — Cool, Thanks.
Copy linkTweet thisAlerts:
@pyroAug 29.2003 — Can't speak for everyone, but I was happy to help, as always... ?
×

Success!

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

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

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