sphinx Posted August 20, 2013 Share Posted August 20, 2013 Hello. Is there a way to make preg_match match all content such as: <a href="/cashback.aspx?linkauth=MATCHEVERYTHINGHERE&mpurl=test&usr=test"> The linkauth has a random string on numbers and characters on a webpage that I want to grab based on that format. Thanks. Quote Link to comment Share on other sites More sharing options...
jazzman1 Posted August 20, 2013 Share Posted August 20, 2013 This will match only letters inside a character class closing with brackets ([ ]), between "=" and "&" symbols. $url = '<a href="/cashback.aspx?linkauth=MATCHEVERYTHINGHERE&mpurl=test&usr=test">'; if(preg_match('~=([A-Za-z]+)&~', $url, $match)) { echo '<pre>'.print_r($match[1], true).'</pre>'; } else { echo 'No match'; } Or.....everything between these two symbols: $url = '<a href="/cashback.aspx?linkauth=MATCHEVERYTHINGHERE&mpurl=test&usr=test">'; if(preg_match_all('~=([A-Za-z]+)&?~', $url, $match)) { echo '<pre>'.print_r($match[1], true).'</pre>'; } else { echo 'No match'; } Quote Link to comment Share on other sites More sharing options...
AbraCadaver Posted August 20, 2013 Share Posted August 20, 2013 I would think with this simple example: $pattern = '#linkauth=([^&]+)'; Quote Link to comment Share on other sites More sharing options...
.josh Posted August 20, 2013 Share Posted August 20, 2013 $pattern = '#(?:\?|&)linkauth=([^&\'"]+)#'; make sure it's linkauth and not someothervarendswithlinkauth. Also cover for if it's the last url param. Quote Link to comment Share on other sites More sharing options...
AbraCadaver Posted August 20, 2013 Share Posted August 20, 2013 Quote Link to comment Share on other sites More sharing options...
sphinx Posted August 20, 2013 Author Share Posted August 20, 2013 This works perfectly. <?php $url = '<a href="/cashback.aspx?linkauth=MATCHEVERYrtyTHINGHERE&mpurl=test&usr=test">'; if(preg_match('~=([A-Za-z]+)&~', $url, $match)) { echo '<pre>'.print_r($match[1], true).'</pre>';} else { echo 'No match'; } ?> However, I need it to grab the content from a specific URL in the exact same format. 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.