Jump to content

PREG match all characters?


sphinx

Recommended Posts

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.

Link to comment
Share on other sites

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'; 
}

Link to comment
Share on other sites

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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.