473,320 Members | 1,939 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,320 software developers and data experts.

Break apart a string at newlines?

Small php question here...

I have a string variable, holding the results from a <textareaof a POSTed
form. I want to create an array from this variable, with each element
containing one line of text from the string.

So, if $myvalue containst

Now is the time
for all good men
to come to the
aid of their country

I end up with this array...

$myvalues[0] = 'Now is the time'
$myvalues[1] = 'for all good men'
$myvalues[2] = 'to come to the'
$myvalues[3] = 'aid of their country'

How can I split this string, at the newlines, into an array? I also don't
want the newlines to be stored in the resulting array.

Thx!
Jul 18 '07 #1
3 2314
"Noozer" <do*******@me.herewrote in message
news:DFnni.128854$1i1.109282@pd7urf3no...
Small php question here...

I have a string variable, holding the results from a <textareaof a
POSTed form. I want to create an array from this variable, with each
element containing one line of text from the string.

So, if $myvalue containst

Now is the time
for all good men
to come to the
aid of their country

I end up with this array...

$myvalues[0] = 'Now is the time'
$myvalues[1] = 'for all good men'
$myvalues[2] = 'to come to the'
$myvalues[3] = 'aid of their country'

How can I split this string, at the newlines, into an array? I also don't
want the newlines to be stored in the resulting array.
Read The Fine Manual:
array explode ( string $delimiter, string $string [, int $limit] )
explode() — Split a string by string
http://fi.php.net/manual/en/function.explode.php

--
Ra*********@gmail.com

"Good tea. Nice house." -- Worf
Jul 18 '07 #2
$myvalues = explode("\n",$myline);

Kind regards,

Harrie Verveer
---
http://www.ibuildings.nl/blog/authors/Harrie-Verveer
Noozer wrote:
Small php question here...

I have a string variable, holding the results from a <textareaof a POSTed
form. I want to create an array from this variable, with each element
containing one line of text from the string.

So, if $myvalue containst

Now is the time
for all good men
to come to the
aid of their country

I end up with this array...

$myvalues[0] = 'Now is the time'
$myvalues[1] = 'for all good men'
$myvalues[2] = 'to come to the'
$myvalues[3] = 'aid of their country'

How can I split this string, at the newlines, into an array? I also don't
want the newlines to be stored in the resulting array.

Thx!

Jul 18 '07 #3
Thanks! I was having problems determining what I should use for a delmiter.

"Harrie Verveer"
<ha******************************************@i-buildings.nlwrote in
message news:Mc******************************@zeelandnet.n l...
$myvalues = explode("\n",$myline);
Noozer wrote:
>Small php question here...

I have a string variable, holding the results from a <textareaof a
POSTed form. I want to create an array from this variable, with each
element containing one line of text from the string.

Jul 19 '07 #4

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

Similar topics

3
by: stuart | last post by:
I am posting data to a sql server database via an asp web form. When retreiving the data the information is all concatenated on one line i.e. When posting in textarea the format looks like: 1....
3
by: yezi | last post by:
Hi: I want to break a string like "30 23 date" into 3 parts in C: int 30; int 23; char string date; Do not know how to get it.
37
by: Xiao Jianfeng | last post by:
Hi, I need to print a long sting, which is two long so it must expand two lines. I know that we can use backslash(\) to explicitly join two lines into a logical line, but this doesn't work for...
2
by: rtilley | last post by:
Hi, While trying to better understand security descriptors on Windows. I've been examining text-based security descriptors. I have the security descriptors on individual lines stored in a text...
7
by: Leonel Gayard | last post by:
Hi all, I had to write a small script, and I did it in python instead of shell-script. My script takes some arguments from the command line, like this. import sys args = sys.argv if args ==...
2
by: JoeW | last post by:
Just wondering as I'm sure someone's done something similar to this before, I need to break up a string, broken up everytime a comma is come across. In example: A, B, C, D, E This can...
3
by: nashak | last post by:
Hello, In a Stored Proc, I am building a string variable. I am getting outputs from 4 different queries and would like the string to have line breaks to display each entry in a different line in...
13
by: Auddog | last post by:
I would like to know how I can break apart a variable. I'm currently passing the variable $id-hours and I would like to break it down. I would like to break down to something similar to: $eid...
14
by: Rob | last post by:
I am trying to perform client-side input validation for a textarea to determine that the number of characters doesn't exceed a certain length. Currently, I am just using str.length, but if the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.