Jump to content

How do keep only text inside a list?


Jeffro

Recommended Posts

(If this is a regex question and should be moved, I apologize.. wasn't sure since I don't know the answer)

If my $description is the following, how would I strip away all the stuff before the list and after it and keep only the contents of the ul?:

 

random text.. blah blah blah..

more text.. blah blah

 

  • list item 1
  • list item 2
  • list item 3

 

random text.. blah blah blah..

more text.. blah blah

 

Link to comment
Share on other sites

This was just done over the weekend. It will yield results that can be displayed in a html file:

<?php
$garbage = 'just some bs <ul><li>text</li><li>text</li><li>text</li></ul>just some more bs';
preg_match_all('/<ul>(.*?)<\/ul>/i', $garbage, $matches);
echo $matches[0][0];
?>

 

$matches[1][0];  will not include the <ul> tags. And with a little work you could get rid of the <li> tags also.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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