- var_dump: documentation ( source)
- preg_match: documentation ( source)
<?php
$expression = "3rd from end";
preg_match('~^(?P<offset>[0-9]+)(?:st|nd|rd|th)* from (?P<position>start|beginning|last|end)+$~', $expression, $matches);
var_dump($matches);