stig1 Posted March 5, 2009 Share Posted March 5, 2009 Hopefully simple question. I have a text string for example: $desc = "There are 50 sets per book, if numbered, the starting number has to be advised by the customer. Each book has a backing board and wrap around writing cover / template."; I would like to turn that into the following: <ul> <li>There are 50 sets per book, if numbered, the starting number has to be advised by the customer.</li> <li>Each book has a backing board and wrap around writing cover / template.</li> </ul> With each li point being controlled by the full stop. Any ideas? Thanks in advance for your help. Link to comment https://forums.phpfreaks.com/topic/148150-text-string-into-ul-li-list/ Share on other sites More sharing options...
jackpf Posted March 5, 2009 Share Posted March 5, 2009 Well, this is how you could get a line break on the end... function wrap($str) { $str = explode('.' $str); foreach($str as $key=>$value) { $return .= $value.'<br />'; } return $return; } Idk, something like that anyway. I don't really know how to go about the <li></li>'s though... Link to comment https://forums.phpfreaks.com/topic/148150-text-string-into-ul-li-list/#findComment-777683 Share on other sites More sharing options...
kenrbnsn Posted March 5, 2009 Share Posted March 5, 2009 Here's one way: <?php $desc = "There are 50 sets per book, if numbered, the starting number has to be advised by the customer. Each book has a backing board and wrap around writing cover / template."; echo '<ul>'; echo '<li>' . implode(".</li><li>",array_filter(explode('.',$desc))) . '.</li>'; echo '</ul>'; ?> Ken (fixed the code after testing it... ) Link to comment https://forums.phpfreaks.com/topic/148150-text-string-into-ul-li-list/#findComment-777688 Share on other sites More sharing options...
stig1 Posted March 5, 2009 Author Share Posted March 5, 2009 Works very well! Thankyou for your help Link to comment https://forums.phpfreaks.com/topic/148150-text-string-into-ul-li-list/#findComment-777692 Share on other sites More sharing options...
jackpf Posted March 5, 2009 Share Posted March 5, 2009 Here's one way: <?php $desc = "There are 50 sets per book, if numbered, the starting number has to be advised by the customer. Each book has a backing board and wrap around writing cover / template."; echo '<ul>'; echo '<li>' . implode(".</li><li>",array_filter(explode('.',$desc))) . '.</li>'; echo '</ul>'; ?> Ken (fixed the code after testing it... ) Hey, just wondering- what does that actually do? I'm not familiar with these functions Link to comment https://forums.phpfreaks.com/topic/148150-text-string-into-ul-li-list/#findComment-777693 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.