Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

converting link format to work with preg_match_all

Status
Not open for further replies.

tianshiz

Programmer
Jun 18, 2010
9
US
Hi,

I'm trying to use preg_match_all with this link:
Code:
...profile.cfm?id=35278&instance=2010%2D06%2D05%2016%3A00%3A00%2E0&y=2010&m=6&d=18&show=future
However, I'm not getting a match. But if I go to that link through the browser, it automatically turns into:
Code:
profile.cfm?id=35278&instance=2010-06-05%2016:00:00.0&y=2010&m=6&d=18&show=future
Running the above link with preg_match_all works, no idea why this is the case.
The only part that changed is the instance in the link, could someone tell me what function was used here? Even chrome could "decode" the link when I simply roll over it.

Thanks for the help,

Tianshiz
 
it is to do with html entity replacements.

Code:
/**
 * function to parse links
 * 
 * params $text string:  the block of text to be parsed
 *
 * returns false: no matches
 * returns array of arrays with each array having the matched url, the query parameters retrieved (as an associative array) and the fragment, if any
*/
function recogniseLinks($text){
  $return = array();
  $pattern = '/(profile.cfm\?.?*) /ims';
  $text = html_entity_decode($text);
  $r = preg_match_all($patttern, $text, $matches);
  if (!$r) return false;
  foreach ($matches[1] as $match):
     $var['url'] = $match;    
     $url = parse_url($match);
     $vars = explode ('&', $url['query']);
     $var['params'] = $vars;
     $var['fragment'] = empty($url['fragment') ? '' : $url['fragment'];
     $return[] = $var;
  endforeach;
  return $return;
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top