devWhiz Posted April 25, 2011 Share Posted April 25, 2011 so I use file_get_contents to get the contents of a webpage, one of the lines has <meta property="og:url" content="http://www.google.com/blahblahblah?s=5cd04d4a7632296b9cdb463d04e82c05" /> I want it to echo only http://www.google.com/blahblahblah so anything between <meta property="og:url" content=" and ?s=5cd04d4a7632296b9cdb463d04e82c05" /> I want to extract and put into a variable this works just fine but I was thinking preg match would be better $thread = explode('<meta property="og:url" content="', $psuc); $thread = explode('?s=', $thread[1]); echo $thread[0]; Thanks Quote Link to comment https://forums.phpfreaks.com/topic/234616-preg-match-help/ Share on other sites More sharing options...
.josh Posted April 25, 2011 Share Posted April 25, 2011 preg_match (regex) can help you out better than what you have now, as far as taking into consideration non-standardized formatting. Things like... - attribute order (ex: content=".." comes before property="..") - spacing between = signs inconsistent (ex: content = "..." vs. content="...") - use of single instead of double quotes (ex: content='...' vs. content="...") - differences in capitalization (ex: CONTENT="..." vs. content="...") - handling when there is no query string on the URL But what would be even better is if you use a DOM parser to parse html content. Quote Link to comment https://forums.phpfreaks.com/topic/234616-preg-match-help/#findComment-1205933 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.