Skip to content

Instantly share code, notes, and snippets.

@aonic
Created December 20, 2010 15:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aonic/748524 to your computer and use it in GitHub Desktop.
Save aonic/748524 to your computer and use it in GitHub Desktop.
<?php
//$url['url'] is the URL as saved in urls table, it has * in it
$temp = preg_quote($url['url'], '/');
$temp = str_replace('\\*','(.*?)',$temp); //Replacing * with (.*?)
$urlToMatch = "/^{$temp}$/"; //Adding /^ and $/ to make preg_match work, ^ and $ are important
//Part taken from old code
$page_requesting = remove_last_slash(remove_index_etc(strip_www($page_requesting)));
$basic_page = remove_last_slash(remove_index_etc(strip_www(remove_query_params($page_requesting))));
//RegEx matching code
//$experimentIDs is an array with list of running experiments, its all part of loops and all.. here just simple version
if($url['url_has_query_param'] == 1) {
//URL has query Params
if(preg_match($urlToMatch , $page_requesting)) {
$experimentIDs[] = $url['experiment_id'];
}
}
elseif($url['url_has_query_param'] == 0) {
//URL has no query Params
if(preg_match($urlToMatch , $basic_page)) {
$experimentIDs[] = $url['experiment_id'];
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment