Go Back   Dreamweaver Club Forums > Hand Coders Forum > PHP
Register FAQ Members List Search Today's Posts Mark Forums Read

Thread Tools Display Modes
Old 11-20-2011, 03:34 PM   #1
Join Date: Jan 2009
Posts: 115
Default preg_match prevents hard break in textarea

My script accepts textarea input unless someone adds a hard break to a line. It has to be connected to my preg_match because a preg_match warning is triggered. The preg_match is:

if(!preg_match("/^([0-9a-zA-Z' \:\;\,\.\!\?-]{2,800})$/", $blog_text))
$error_mess_blog = "Some blog characters used have not been accepted. Please try again.";

If a user uses a hard break and sends the data the text returns to what it was and the warning appears. It, seems the preg_match does not like the hard break. I'm assuming that when you press return an html break tag is registered (although it doesn't appear on the source). Is the preg_match objecting to the tag ? If it is, how do you get round the problem ? If it isn't, what can I do ?
Basically, this text area (the one used to post this message) is doing what my textarea can't.
Thanks in advance, for any answers.
songboy is offline   Reply With Quote
Old 11-24-2011, 01:28 PM   #2
davidj's Avatar
Join Date: Sep 2005
Location: The Toon (newcastle upon Tyne)
Posts: 8,256

have you tried using nl2br on the the contents before using the regex
Would you like to learn PHP from me? Check out -> www.codezenith.co.uk
davidj is offline   Reply With Quote
Old 11-25-2011, 07:49 PM   #3
Join Date: Jan 2009
Posts: 115

Hi dj and all.
Yes, nl2br was part of the solution.
The first thing was to stop the preg_match refusing a line break. I had to use this in the preg_match:

if(!preg_match("/^([0-9a-zA-Z' \:\;\,\.\!\?\r\n-]{2,800})$/", $blog_text))...notice the \r\n

Then, in the presentation I had to add this:

<div id="Layer25"><?php echo nl2br($blog_text) ?></div>
Now things are fine.
All the best -
songboy is offline   Reply With Quote

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

All times are GMT. The time now is 06:21 PM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2018, vBulletin Solutions, Inc.
Copyright 2006 DreamweaverClub.com