473,785 Members | 2,831 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

php form textarea saving to file: ^M problem

Dear programmers,

I have a form:

<form action=".." method="post">
<textarea name="text1"></textarea>
</form>

And a php file that saves this variable to a file:

$fp = fopen("file.txt ",a);
fwrite($fp,$_PO ST[text1]);
fclose($fp);

When I fill the textarea with the following text:

1,2,
3,

4.

In the file, the following appears (reading the file with Midnight
Commander on Linux):

1,2,^M
3,^M
^M
4.

In a new script, I want to parse this file. Every empty line should be
detected. How should I do that? if ($line == "\n") { .. } doesn't work,
because the line actualy contains ^M\n. When saving the contents of the
textarea to the file, I don't know how to strip the ^M characters.

Any ideas?

much thanks in advance!

Martin
(The Netherlands)
Jul 17 '05 #1
3 2832
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Martin Herrman wrote:
In a new script, I want to parse this file. Every empty line should be
detected. How should I do that? if ($line == "\n") { .. } doesn't work,
because the line actualy contains ^M\n. When saving the contents of the
textarea to the file, I don't know how to strip the ^M characters.


How about if("\r\n" == $line) { ... }
Bob
-----BEGIN PGP SIGNATURE-----
Comment: B. Johannessen <bo*@db.org> - http://db.org/contact/en/

iD8DBQFAPKM0ooi sUyMOFlgRAmaLAK CBy79CT/pnKLm217Gg3pBar nwnmwCfaojm
aXfeZBraCgLzl7C jg5NTInA=
=Xpn5
-----END PGP SIGNATURE-----
Jul 17 '05 #2
Martin Herrman:
Dear programmers,

I have a form:

<form action=".." method="post">
<textarea name="text1"></textarea>
</form>

And a php file that saves this variable to a file:

$fp = fopen("file.txt ",a);
fwrite($fp,$_PO ST[text1]);
fclose($fp);

When I fill the textarea with the following text:

1,2,
3,

4.

In the file, the following appears (reading the file with Midnight
Commander on Linux):

1,2,^M
3,^M
^M
4.

In a new script, I want to parse this file. Every empty line should be
detected. How should I do that? if ($line == "\n") { .. } doesn't work,
because the line actualy contains ^M\n. When saving the contents of the
textarea to the file, I don't know how to strip the ^M characters.


In case you didn't know, unix uses \n for newlines, Mac uses \r (older macs
anyway, OSX is based on FreeBSD and uses \n) and Windows uses \r\n.

I'd suggest making sure that newlines are always represented the same,
regardless of what system the data was typed in on. The simplest way to
achieve this is probably to do a str_replace(). You want to first replace
any \r\n with \n, then any \r with \n. Thus:

str_replace(Arr ay("\r\n", "\r"), "\n", $input);

Do this just before you write the data to file.

André næss
Jul 17 '05 #3
if(!trim($line) ) { ...

Uzytkownik "Martin Herrman" <m.*******@stud ent.tue.nl> napisal w wiadomosci
news:pa******** *************** *****@student.t ue.nl...
Dear programmers,

I have a form:

<form action=".." method="post">
<textarea name="text1"></textarea>
</form>

And a php file that saves this variable to a file:

$fp = fopen("file.txt ",a);
fwrite($fp,$_PO ST[text1]);
fclose($fp);

When I fill the textarea with the following text:

1,2,
3,

4.

In the file, the following appears (reading the file with Midnight
Commander on Linux):

1,2,^M
3,^M
^M
4.

In a new script, I want to parse this file. Every empty line should be
detected. How should I do that? if ($line == "\n") { .. } doesn't work,
because the line actualy contains ^M\n. When saving the contents of the
textarea to the file, I don't know how to strip the ^M characters.

Any ideas?

much thanks in advance!

Martin
(The Netherlands)

Jul 17 '05 #4

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

Similar topics

2
2918
by: Asad | last post by:
I have a form on a page that has several textareas, and textboxes inside a table (so the table containing the textboxes is also inside the FORM tag). I want to replace the textareas with simple text instead. But I want to keep the format of my page EXACTLY the same. However, the problem is that ... 1) Javascript won't let me create say a one-cell TABLE containing some text (e.g. textarea's value) and then insertBefore an element in the
8
3713
by: david.lindsay.green | last post by:
Hello all, I am quite new a web scripting and making web pages in general and I have stumbled across a problem I have as yet been unable to solve. I am trying to take the contents of a textarea box and save it to a file. This step is not to hard however the contents of the textarea is mostly latex source so it contains just about every special character you can imagine. My question is this, how do I save an exact copy of the textarea...
2
3633
by: alwaysintune | last post by:
I'm using the McFedries email form, and I can't seem to get an upload form to work. Instead of it saving to my server, I want it to send the information and the picture to my email. Here is the html for my form. If anyone could help, that'd be greatly appreciated. <form action="http://www.mcfedries.com/mailform/mailform.asp" method="POST"> <input type=hidden name="MFAddress" value="My email address"> <input type=hidden name="MFCode"...
5
2235
by: Schraalhans Keukenmeester | last post by:
I want to build a very basic online text editor, to allow customers to modify their own sites' html content using a simple form with textarea element. I read the HTML file like so: <?PHP function EditText ($filepath) {
1
2551
by: fugaki | last post by:
Hi everyone I'm learning asp, and i downloaded this script to teach me how to post form data from a webpage to an access database. I put it on the server so i could make sure that it worked, and everything was fine, so i changed the variable names (the names of the form elements, and the names of the rows in access) so that it would be more correct to what i am using it for. Now once I did that, it gave me an error on line 24 which was the...
4
2055
by: rn5a | last post by:
I am storing the physical path of images, along with 3 more columns, in a MS-Access DB table. I want to provide users the option to change this physical image path (as well as the records in the other columns) for which I am using the *File* Form element. The column under which the physical paths are stored is the 4th column in the DB table. Users first come to a page that displays the distinct records existing in column1 in the above...
3
1758
by: mirianCalin | last post by:
the code saves the category, image title, image, and feature.. but the problem is that the "feature" is not saved, but the others were saved.. this is the data types of my table category = text title = text image = longblob feature = text in html, the users input the feature in (textarea)..
3
2332
by: saytri | last post by:
I am displaying the contents of a textfile in a textArea. I want that when i edit this text in the textArea it is automatically saved in the textfile. I have wriitten this code, but the problem is that when i edit the text in the text Area it isn't saving it on the textfile. What do i have wrong? Thanks a lot. import java.awt.BorderLayout; import java.io.DataInputStream; import java.io.File; import java.io.FileInputStream; import...
4
2253
by: bleachie | last post by:
Hi, My e-mail form seems to work fine in IE7 but doesn't work in FireFox2.0 - it just goes to the index.php instead of echoing the completed message. Hope someone can help me out. Form.html <html> <style type="text/css"> <!--
0
9480
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10324
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10147
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9949
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8971
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7499
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3645
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2879
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.