Regex match with newlines??? need help

Discussion in 'PHP' started by DrVillain, May 23, 2010.

  1. #1
    so im trying to grab the headers from html.

    this is what i got so far

    preg_match('/<head>(.*?)<\/head>/', $html,$res))

    but it doesnt work for multiple lines.

    whats up?
     
    DrVillain, May 23, 2010 IP
  2. TheDataPlanet.com

    TheDataPlanet.com Well-Known Member

    Messages:
    503
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    108
    #2
    TheDataPlanet.com, May 24, 2010 IP
  3. koko5

    koko5 Active Member

    Messages:
    394
    Likes Received:
    14
    Best Answers:
    1
    Trophy Points:
    70
    #3
    Last edited: May 24, 2010
    koko5, May 24, 2010 IP
  4. TheDataPlanet.com

    TheDataPlanet.com Well-Known Member

    Messages:
    503
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    108
    #4
    That's a nice tip, koko! These are much better as it's native, faster and easier.
     
    TheDataPlanet.com, May 27, 2010 IP
  5. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #5
    and slower
     
    danx10, May 28, 2010 IP
  6. flexdex

    flexdex Peon

    Messages:
    104
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #6
    ..and you will get only the meta tags, nothing else. get_headers is completely the wrong way to go, that will give you http servers header, not the headers from html.

    
    if (preg_match('%<HEAD[^>]*>(.*?)</HEAD>%six', $subject, $regs)) {
    	$result = $regs[1];
    } else {
    	$result = "";
    }
    
    Code (markup):
     
    Last edited: May 28, 2010
    flexdex, May 28, 2010 IP