supertrucker Posted May 29, 2009 Share Posted May 29, 2009 I'm having trouble understanding how the preg_match function works, furthermore, the code examples I read further confuse me! I use this code below as part of a "bookmarklet" for my site, but the code was essentially copy and pasted (it's utilizing cUrl functions). I basically understand what the preg_match function does, it parses text. What I don't understand is how get it to do what you want. The code below works for getting the "<title>" tag from a remote web page. Could somebody please explain the different parts of the preg_match function below? For instance, what are all the slashes "\/" for? What's with the (.+)? Why does the closing title tag have two slashes? What does the "/siU" mean? include("get_web_page.php"); $url=$_REQUEST['URL']; $header=get_web_page($url); $content=$header['content']; $url=$header['url']; $cerror=$header['errno']; /* get page's title */ preg_match("/<title>(.+)<\/title>/siU", $content, $matches); $title = $matches[1]; Thanks for any help! Link to comment Share on other sites More sharing options...
Ingolme Posted May 29, 2009 Share Posted May 29, 2009 The first parameter of the preg_match() function is a Regular Expression. It's a form of code that defines a set of rules for a text to follow.W3Schools has a reference for Regular Expressions here:http://w3schools.com/jsref/jsref_obj_regexp.aspFor a more detailed tutorial, go to http://regularexpressions.info Link to comment Share on other sites More sharing options...
supertrucker Posted May 29, 2009 Author Share Posted May 29, 2009 Thank you, that second link has a very well put together explanation! Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.