Dear All,
I have an URL address of the form
/string/anotherstring/yetanotherstring21
Any number of /strings/ can occur in the address - can anyone tell me if I can
[a] Detect whether or not a number has occurred after 'yetanotherstring'
and if so
Extract this number into a variable
Sometimes, a number will not appear at the end and therefore this case needs to be discounted.
Many thanks
Mark
Regex for this?
Moderator: General Moderators
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
untested
Code: Select all
preg_match_all('#/\w*((\d+)\w*)*$#',$url,$matches)Hi feyd/weirdan - thanks for the response. It doesn't seem to be working I'm afraid. I'm using the following PHP code:
Code: Select all
// Check if a property information page is called via /<type>X
if( preg_match('#/\w*((\d+)\w*)*$#',$url,$match2) && $pagecall != true )
{
if(!empty($match2[1]))
{
$propcall = true;
echo 'Property Info: '.$match2[2];
}
}I'd just do:
Code: Select all
preg_match('#[0-9]*$#', basename($url), $match);
if(!empty($match[0])){
echo $match[0]; //it did have a number on the end
} else {
echo 'no ending numbers';
}