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
https://forums.phpfreaks.com/topic/235364-how-do-keep-only-text-inside-a-list/
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.

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.