/    Sign up×
Community /Pin to ProfileBookmark

maintaining paragraphs in textareas

hi all,

hopefully not too complicated but I’m not so strong with php and was wondering if anyone could point me in the direction of how to achieve the following:

I’ve got a job site I built which allows people to post a full job description in a textarea which is submitted to a mysql db along with other fields such as location/job title etc.

In the job description I’d like users to be able to paste in all the text and have the field wrap each paragraph in a <p> tag in the page once it’s saved.

At the moment, as there’s no specific processing it just lists all the text in a solid block with no formatting.

I’ve tried tinyeditor which works alright but for my needs, I don’t want users to be able to add all the other formatting like bold, italic etc and change colours and also the source it spits out is horrific.

Is there a way I can post in a couple of paragraphs of text into my text field and have it render on the page in <p> tags?

Many thanks,

James.

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@NogDogDec 26.2007 — Simple solution to force line breaks:
[code=php]
echo "<p>" . nl2br($text) . "</p>n";
[/code]

More elegant solution to break the text up into separate HTML paragraphs:
[code=php]
echo "<p>" . preg_replace('/[rn]+/', "</p>n<p>", $text) . "</p>n";
[/code]
Copy linkTweet thisAlerts:
@jambleauthorDec 26.2007 — Thanks NogDog,

I'd done a bit of googling and found the nl2br function which was half way so it's good to know it can be expanded to wrap lines in para tags.

I'll give it a go ?

Cheers,

J.
×

Success!

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