Forum Moderators: coopster

Message Too Old, No Replies

textarea to single line

convert a text area to a single line

         

cached

3:47 pm on Jul 31, 2004 (gmt 0)

10+ Year Member



how do I convert a text area where somebody entered:

hi guys
my
name
is
bob

(for example) to: hi guys#my#name#is#bob?

on the next form

dreamcatcher

4:33 pm on Jul 31, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi cached,

I think explode() might be what you want. To split each keyword with a hash, try something like:

$text = explode("\r\n", $text);

foreach ($text as $newtext)
{

echo $newtext . "#";

}

Think that might work.

coopster

6:27 pm on Jul 31, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld, cached!

Yes, that solution will indeed work. You could also use str_replace() [php.net].

$text = str_replace("\r\n", '#', $text);

ergophobe

7:48 pm on Jul 31, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



How is post data sent? Will the new line in POST data always be CRLF or will it depend on the client OS? If it does (or even might) depend on the client OS, I would go with:

$text = str_replace("\n", '#', $text); // *nix and Win
$text = str_replace("\r", '#', $text); // Mac and Win

Tom

cached

10:47 pm on Aug 1, 2004 (gmt 0)

10+ Year Member



dream catcher's idea works :) thanks

ergophobe

1:10 am on Aug 2, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



My comment still holds. If the data comes in using the same newline as the OS, that code will only work on a Windows system.

Now, I don't know offhand exactly how newlines are transmitted in post data, but I'm guessing that they just use whatever the OS uses (menaing that your code won't work if the client is on a Mac or *nix). Easy to test - get someone on a Mac to try it and see how it works.

Tom