TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   General (http://www.talkphp.com/general/)
-   -   Split a string (http://www.talkphp.com/general/5018-split-string.html)

Jmz 10-12-2009 08:21 PM

Split a string
 
I have a string that will look like:

Code:

Line 1;Line 2;Line 3
Basically the words will be separated by a semi-colon. How can I split this string and then display them like:

Code:

<li>Line 1</li>
<li>Line 2</li>
<li>Line 3</li>


Jmz 10-12-2009 08:38 PM

Ooops, was easier than I thought! Incase anybody else needs the same thing.

PHP Code:

$string 'Line 1;Line 2;Line 3;';
$string explode(';',$string);
foreach (
$string as $value){
echo 
"<li>".$value."</li>";
}
unset(
$value); 


Village Idiot 10-12-2009 09:41 PM

That is probably the best way to do it. Thanks for posting the result when you found it.

adham is me 10-13-2009 09:42 PM

you are really a good man seeking spreading knowledge

thanks for posting solution

cachepl0x 10-13-2009 10:33 PM

You forgot an "s" on line three in "$string." ;)

Nice find.

Jmz 10-19-2009 12:24 PM

Thanks for that, I've updated it incase somebody wants to use it.


All times are GMT. The time now is 12:34 AM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0