Implementation of RFC-6570 (Template URI) in a single PHP function