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:

Username:   Password:
Add Reply
PHP: Split string at newline?
Topic Started: Mar 7 2005, 10:52 PM (2,560 Views)
Ben
Member Avatar
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:

Code:
 
Important:
Alert:
Muwahahaha:
Warning:


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. :)
Offline Profile Quote Post Goto Top
 
Seth
Member Avatar
I has a pony
[ *  *  *  *  *  *  *  *  * ]
http://us2.php.net/explode

<?php $myArray = explode("\n", $theString); ?>
Offline Profile Quote Post Goto Top
 
Ben
Member Avatar
Quantum-locked when observed.

Ah, so easy! Thanks. :D
Offline Profile Quote Post Goto Top
 
1 user reading this topic (1 Guest and 0 Anonymous)
« Previous Topic · Technology Chat · Next Topic »
Add Reply