Page 1 of 1

simple regex change

Posted: Sun Mar 20, 2005 6:11 am
by mjseaden
Hi there,

I know that the following code

Code: Select all

// Check if a pagecall is made using /pX at the end of the URL
if (preg_match('/\/(p??)(\d+)$/', $url, $match)) 
{ 
  if (!empty($match[1])) 
  { 
    $pagecall = true; 
  } 
}
checks whether the $url (which is $REQUEST_URI) contains /pX at the end, where X is any number, and returns X into $match[].

However, can anyone tell me how to change it so it detects .pX at the end of the URL, instead of /pX (i.e. a dot instead of forward slash).

Many thanks

Mark

Posted: Sun Mar 20, 2005 6:39 am
by Chris Corbyn
If all you need is the value of X then why have (..) around the p and what are the double ?? for?

Code: Select all

preg_match('/\.p(\d+)$/i', $url, $match); //$match[1]is the value of x
Also, if you need to check if it matched, no need for the !empty() thing... just do

Code: Select all

if(preg_match(....)) {
    $pagecall = true;
}
:wink: