SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict
    Join Date
    Nov 2002
    Location
    Maryland
    Posts
    307
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Need help with extracting a string from a string

    I have the following string:

    PHP Code:
    $text '<p><strong>2010</strong></p>
    <ul>
        <li>Content Content Content Content Content Content </li>
        <li>Content Content Content Content Content Content </li>
    </ul>
    <p><strong>2009</strong></p>
    <ul>
        <li>Content Content Content Content Content Content </li>
        <li>Content Content Content Content Content Content </li>
    </ul>'

    I need a way to extract the first paragraph text only.

    PHP Code:
    echo extract($text); 
    output <p><strong>2010</strong></p>

    What is the best way to do this? thanks

  2. #2
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    73 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    echo array_shift(explode('</p>',$text))."</p>"

  3. #3
    SitePoint Addict
    Join Date
    Nov 2002
    Location
    Maryland
    Posts
    307
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    StarLion, That works. Thanks!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •