/    Sign up×
Community /Pin to ProfileBookmark

New line problem

How can I avoid a full blank line while reading information from a text file.
Im going to parse this text and insert the information into a database however there are some blank lines and these get me in trouble because Im parsing the text using explode and Im parsing it according to the rn at first.So it gets the blank lines as well.But It mustnt get.
anyone helps??

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@aaronbdavisMar 07.2006 — read the entire file into a variable. The do a preg_replace on successive occurances of newline.

[code=php]$subject = file_get_contents($file_name);
$newline = "rn";
$replace = "";
$pattern = "/$newline(s)*$newline/";
$subject = preg_replace($pattern,$replace,$subject);
$subject_array = explode($newline, $subject)[/code]


I haven't tested this but i think it will work.
Copy linkTweet thisAlerts:
@bokehMar 07.2006 — [code=php]$output = preg_replace('/[rn]{2,}/', "rn", $input);[/code]
×

Success!

Help @guess 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.18,
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,
)...