Quick Question

Discussion in 'PHP' started by Nerve, Nov 28, 2009.

  1. #1
    if I have a string, what function do I use to get certain content from it? I havnt coded in years So I kind of forget.


    For Example:

    $string = "<a href='http://google.com'>TEXT HERE THAT I WANT TO EXTRACT</a>"

    How would I extract the text on the link, in this case its "TEXT HERE THAT I WANT TO EXTRACT"

    Thanks
     
    Nerve, Nov 28, 2009 IP
  2. temp2

    temp2 Well-Known Member

    Messages:
    1,231
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    150
    Digital Goods:
    2
    #2
    just use preg_split

     
    temp2, Nov 28, 2009 IP
  3. spc

    spc Well-Known Member

    Messages:
    136
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    125
    #3
    I second to that, but a better approach should be as follows:

    
    $string = "<a href='http://google.com'>TEXT HERE THAT I WANT TO EXTRACT</a>";
    preg_split("/>([^<]*)</", $string);
    
    Code (markup):
     
    spc, Nov 28, 2009 IP