ShootingBlanks Posted November 19, 2007 Share Posted November 19, 2007 Hello. I have a long string of text. Throughout the string, there is the string of characters "&&&&" (four ampersands). Whenever that "&&&&" shows up, I'd like to split the string, and put each split into a list... ...so, if the string were: Item 1&&&&Item 2&&&&Item 3 Then I'd want to create this: <ul> <li>Item 1</li> <li>Item 2</li> <li>Item 3</li> </ul> Can anyone help me with the code to do that??? Thanks! Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted November 19, 2007 Share Posted November 19, 2007 Try something like this: <?php $str = 'Item 1&&&&Item 2&&&&Item 3'; echo '<ul><li>' . implode('</li><li>',explode('&&&&',$str)) . '</li></ul>'; ?> Ken Quote Link to comment Share on other sites More sharing options...
Wes1890 Posted November 19, 2007 Share Posted November 19, 2007 // the string $string = "Item 1&&&&Item 2&&&&Item 3"; // put in arrays $split = explode("&&&",$string); // start echo "<ul>"; for ($i=0; $i<count($split);$i++) // for each item { // echo it echo "<li>".$split[$i]."</li>"; } //end echo "</ul>"; Quote Link to comment Share on other sites More sharing options...
nuxy Posted November 19, 2007 Share Posted November 19, 2007 Wes1890, your code does exactly the same as kenrbnsn's, your's is just allot more code, and pointless. Don't reinvent the wheel. (; Quote Link to comment Share on other sites More sharing options...
ShootingBlanks Posted November 19, 2007 Author Share Posted November 19, 2007 Thanks everyone! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.