kratsg Posted October 23, 2007 Share Posted October 23, 2007 $data = file_get_contents('http://www.yahoo.com'); $pattern = "/<title>([^<]*)<\/title>/"; preg_match($pattern, $data, $matches); How does the $matches part work? I understand it is AN array, but how do you know what goes into $matches[0], $matches[1]... $matches? I'm a bit lost on that (and would it be the same for preg_match)? Quote Link to comment Share on other sites More sharing options...
trq Posted October 23, 2007 Share Posted October 23, 2007 From the manual... If matches is provided, then it is filled with the results of search. $matches[0] will contain the text that matched the full pattern, $matches[1] will have the text that matched the first captured parenthesized subpattern, and so on. Quote Link to comment Share on other sites More sharing options...
kratsg Posted October 23, 2007 Author Share Posted October 23, 2007 What would be the text that matched the full pattern? o_o The <title>stuff</title> part? Also, if you used parentheses like so: $pattern = "/^(ab|cd)([^xyz]*)xyz/"; Would $matches[1] contain the "ab" or the "cd" depending on the text? Quote Link to comment Share on other sites More sharing options...
trq Posted October 23, 2007 Share Posted October 23, 2007 What would be the text that matched the full pattern? o_o The <title>stuff</title> part? Yes, the <title>stuff</title> part part from your last post. Would $matches[1] contain the "ab" or the "cd" depending on the text? $matches[1] would contain whatever matched ab|cd, $matches[2] would contain whatever matched [^xyz]*. Quote Link to comment Share on other sites More sharing options...
kratsg Posted October 23, 2007 Author Share Posted October 23, 2007 Now I finally understand... and I see teh LIGHT! :-o 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.