Regular Expression issue
- by Christian Sciberras
I have the following URL structure which I need to match to and get the particular id from:
/group/subgroup/id-name
In short, I need to translate a URL like the following:
/Blue Products/Dark Blue/5-Blue_Jelly
To:
/?pagename=Blue Products&model=5
IMPORTANT: I don't need to match group, I already have group.
Example code:
<?php
foreach($cats as $cat)
$cmd->rewrite('/\/'.$cat.'\/unused\/(ID)-unused\//','/?pagename='.$cat.'&model=%ID%');
?>
Edit:
This is the completed code:
if($groups->count()){
$names=array();
foreach($groups->rows as $row)
$names[]=preg_quote($row->group);
$names=implode('|',$names);
$regex='('.$names.')/([^/]+)/([0-9]{1,})-([^/]+)/?$';
CmsHost::cms()->rewrite_url($regex,'index.php?pagename=Products',true);
}