Jump to content

preg match help


devWhiz

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/234616-preg-match-help/
Share on other sites

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. 

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/234616-preg-match-help/#findComment-1205933
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.