Jump to content

text string into ul li - list


stig1

Recommended Posts

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

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...

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... :))

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 :P

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.