[nycphp-talk] preg_match (related to Many pages one script discussion)

Michael B Allen ioplex at
Mon Aug 6 21:46:36 EDT 2007


It so happens I'm working on a CMS component and the 'Many pages one
script' discussion has inspired me to add mod_rewrite capability. I
have a catch-all RewriteRule that just sends everything through
index.php at the top of which I have a "handler table" that maps the
REQUEST_URI to a handler class. I'm using preg_match to do the match
and collect the parameters.

So an example regex looks like:


This works fine with REQUEST_URIs like:


but it does not match any of the following:


I would like to match these. For example, if the day parameter is not
provided the match array returned by preg_match should simply have one
fewer elements.

So how does one designate parts of a preg_match expression as optional?


More information about the talk mailing list