getNumberFromEndOfUrl() pulling number from middle of a URL?

3 posts by 2 authors in: Forums > CMS Builder
Last Post: May 24, 2010   (RSS)

By dougdrury - May 24, 2010 - edited: May 24, 2010

CMSB 2.03
I have a URL '/projects.php?project_category=BMS%2FDDC+Controls'

I want this URL to NOT match with any numbers to show a set of records, but this url could also look like this '/projects.php?project_category=BMS%2FDDC+Controls&num-123' and I want CMSB to find the record 123.

I have tried to use getNumberFromEndOfUrl() to just look at the end of the URL to see if it has a number, and it ALWAYS pulls the number 2 from the %2 in the URL if there is no num-1234 at the end. Am I doing something wrong? I have tried getNumberFromEndOfUrl(1) as well.

I want it to see if there is an alpha at the end, return 0 and if there is a numeric at the end of the url, return that number.

Thanks,
Doug

Re: [dougdrury] getNumberFromEndOfUrl() pulling number from middle of a URL?

By Dave - May 24, 2010

Hi Doug,

Yea, it actually gets the last number in the url even if it's not at the end of the url. It does that so you can have urls like this: ?article-name-####.html

Try this:
// get last number in url
$lastNumber = 0;
if (preg_match("/(\d+)$/", @$_SERVER['QUERY_STRING'], $matches)) {
$lastNumber = $matches[1];
}

print "Last Number: $lastNumber<br/>\n";


Let me know if that works for you.
Dave Edis - Senior Developer
interactivetools.com