Jump to content

PREG match all characters?


sphinx

Recommended Posts

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

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.

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.