Regular Expression issue
Posted
by
Christian Sciberras
on Stack Overflow
See other posts from Stack Overflow
or by Christian Sciberras
Published on 2011-02-04T12:17:23Z
Indexed on
2011/02/04
15:25 UTC
Read the original article
Hit count: 223
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);
}
© Stack Overflow or respective owner