473,387 Members | 1,590 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

The woes of a PHP form submission

Good evening to the skilled Ladies and Gentlemen of the PHP world. I
am fairly new to all of this but learning quickly. I have run in to a
need to remove blank lines from a form submission after its sent back
to the web server for processing by a PHP document.

I have a textarea that users can paste lines of text in to and submit
them for inclusion in to a database. Every aspect is working
perfectly, except one. No matter what I try, I cannot get rid of
simple blank lines from the form submission.

$theLines = $HTTP_POST_VARS['userSubmitted'];

This variable ($theLines) now contains the contents from the textarea.
I have tried using ...

$theLines = explode("\n", $theLines);

and

$theLines = explode("\r", $theLines);

But all of the blank lines are still there. If anyone has some
snippet that they would share, I would be very grateful.

With great respect,

Martin
Jul 16 '05 #1
2 2939
Martin the Mac Addict wrote...
[...]
But all of the blank lines are still there. If anyone has some
snippet that they would share, I would be very grateful.


<?php
function remove_blank_lines($txt) {
str_replace("\r", '', $txt); ## remove all "\r"s
## and convert all double enters (and triple ...) to one enter
while (strpos($txt, "\n\n") !== false)
$txt = str_replace("\n\n", "\n", $txt);
return $txt;
}
?>

NOTE: this was typed into google without being checked.
Jul 16 '05 #2
ad***@minoguetech.com (Martin the Mac Addict) wrote in message
news:<e4************************@posting.google.co m>...

I have a textarea that users can paste lines of text in to and submit
them for inclusion in to a database. Every aspect is working
perfectly, except one. No matter what I try, I cannot get rid of
simple blank lines from the form submission.


This may be somehow related to the end-of-line character issue.
End of line in DOS/Windows is a two-character sequence "\r\n",
in Unix, a single character "\n", and in MacOS, a single character
"\r". So if you want to strip end-of-line characters from a form
submission, you should try something like this:

$theLines = $HTTP_POST_VARS['userSubmitted'];
$theLines = str_replace("\n", '', $theLines);
$theLines = str_replace("\r", '', $theLines);

Also, take a look at the script you use to render the submission.
If you have something like this:

<textarea>
<?php
echo $theLines;
?>

</textarea>

then the extra blank line actually comes from your HTML, not your
PHP...

Cheers,
NC
Jul 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Tom | last post by:
I have created the following code for a product select/payment form (don't know if there is a better way) and I have been trying to make the following changes (unsuccessfully so far): 1) ...
19
by: Pete | last post by:
I have form/select which executes a function using onchange. No problem. However, when I validate the page with a strict HTML 4.01 doctype at http://validator.w3.org, it demands either an action or...
5
by: Richard Cornford | last post by:
I am interested in hearing opinions on the semantic meaning of FORM (elements) in HTML. I have to start of apologising because this question arose in a context that is not applicable to the...
3
by: Jack | last post by:
Hi, I have a asp input form of a financial report. Here most of the fields are text boxes where the user need to input the values corresponding to an item. However, there are few items which are...
2
by: Andy Goldstein | last post by:
I have a table where all the TRs have an onClick handler registered. One (and only one) of the rows has 2 text input boxes, where each textbox has an onChange handler registered. Both the onClick...
8
by: yawnmoth | last post by:
Say I have the following HTML: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title></title> </head> <body> <form action="">
6
by: Oleg Konovalov | last post by:
Hi, I have a Java/JavaScript GUI application where I perform a lot of long DB operations , which takes 5-60 secs to perform. Sometimes user double-clicks the button or just gets impatient and...
1
by: Homer | last post by:
Hi, I just got a requirement from my HR department to automate their form submission process and integrate it into the Intranet project that I had just completed Phase 1 of. Because of the...
8
Megalog
by: Megalog | last post by:
Hey guys.. my turn to ask a question: I'm having a weird issue with a form I've reworked. This form has a combo box, which when used is changing the recordsource of a subform. This subform has...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.