dsaba Posted December 4, 2007 Share Posted December 4, 2007 $str = '<head> <b>one</b> <b>two</b> <b>three</b> <b>four</b> <b>five</b> </head> <b>six</b> <bseven</b>'; $pat = '~<head>.*(<b>(.*?)</b>).*</head>~'; $lalaz = preg_match_all($pat, $str, $out); print_r($out); it outputs: Array ( [0] => Array ( ) [1] => Array ( ) ) I want to match everything inside the <b> bold tags, but only if these bold tags occur within the <head</head> tags.. What am I doing wrong? Quote Link to comment Share on other sites More sharing options...
effigy Posted December 4, 2007 Share Posted December 4, 2007 . will not match new lines without the /s modifier. Quote Link to comment Share on other sites More sharing options...
dsaba Posted December 4, 2007 Author Share Posted December 4, 2007 could you give me an example of where I would put this modifier to achieve my wanted results? I tried: $pat = '~<head>.*(<b>(./s*?)</b>).*</head>~'; $pat = '~<head>.*(<b>(.*?/s)</b>).*</head>~'; same results on both Quote Link to comment Share on other sites More sharing options...
effigy Posted December 4, 2007 Share Posted December 4, 2007 The syntax is delimiter pattern delimiter modifiers, which is your case would be ~pattern~s. Quote Link to comment Share on other sites More sharing options...
dsaba Posted December 4, 2007 Author Share Posted December 4, 2007 This is the result I get. I want to grab all of them only grabs the last one 'five' and not the rest, how can I make it do that? Array ( [0] => Array ( [0] => <head> <b>one</b> <b>two</b> <b>three</b> <b>four</b> <b>five</b> </head> ) [1] => Array ( [0] => <b>five</b> ) [2] => Array ( [0] => five ) ) Quote Link to comment Share on other sites More sharing options...
dsaba Posted December 4, 2007 Author Share Posted December 4, 2007 $pat = '~<head>.*(<b>(.*?)</b>).*</head>~s'; I want to say: look in between <head> </head> match all patterns beginning with <b> and followed by any character and any amount of any characters followed by </b> from the regex tutorial here on phpFreaks I am confused by some of the metacharacters: when I say "~<head>.* i take it to mean start with <head> and must have only 1 of these yet * means 0 or more of these.. I don't see why both of these are together like this Quote Link to comment Share on other sites More sharing options...
effigy Posted December 4, 2007 Share Posted December 4, 2007 This isn't possible with one expression. I think the best solution is to grab all of the data in the head tag with ~<head>(.*?)</head>~ then run a preg_match_all of ~< b>(.*?)< /b>~ against this. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.