| We hope you enjoy your visit. You're currently viewing our forum as a guest. This means you are limited to certain areas of the board and there are some features you can't use. If you join our community, you'll be able to access member-only sections, and use many member-only features such as customizing your profile, sending personal messages, and voting in polls. Registration is simple, fast, and completely free. Join our community! If you're already a member please log in to your account to access all of our features: |
| PHP: Split string at newline? | |
|---|---|
| Tweet Topic Started: Mar 7 2005, 10:52 PM (2,560 Views) | |
| Ben | Mar 7 2005, 10:52 PM Post #1 |
|
Quantum-locked when observed.
![]()
|
I'm storing the value of a database field in a variable called $prefixes. The variable will always contain a series of words (usually only one word) separated by a newline. What I'd like to do is split the $prefixes string into a series of strings (or even just an array). So if $prefixes contained this:
Then the resulting split would be an array with the first element as "Important:", the second as "Alert:", et cetera. How would I go about doing this in PHP? Would I use the preg_split function, and if so, how? After I have set up this array, I will use it in a while() loop that echoes each array value as an option in a SELECT box. Thus, it will create a dropdown menu with the first option being "Important:", et cetera. Thanks for any help.
|
![]() |
|
| Seth | Mar 8 2005, 02:07 AM Post #2 |
|
I has a pony
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]()
|
http://us2.php.net/explode <?php $myArray = explode("\n", $theString); ?> |
![]() |
|
| Ben | Mar 8 2005, 05:40 PM Post #3 |
|
Quantum-locked when observed.
![]()
|
Ah, so easy! Thanks.
|
![]() |
|
| 1 user reading this topic (1 Guest and 0 Anonymous) | |
| « Previous Topic · Technology Chat · Next Topic » |
| Track Topic · E-mail Topic |
10:14 PM Jul 10
|







![]](../../../../0/1/0/p601690/pipright.png)
10:14 PM Jul 10