- substr_count: documentation ( source)
- var_dump: documentation ( source)
- strpos: documentation ( source)
- array_slice: documentation ( source)
- explode: documentation ( source)
- trim: documentation ( source)
<?php
$found = null;
$route = '/_ticket/show/xxx';
foreach ( explode( '/', trim( $route, '/' ) ) as $part => $r )
{
$uscore = strpos( $r, '_' );
$times = substr_count( $r, '_' );
if ( 1 != $times || 0 != $uscore )
{
continue;
}
$found = $part;
break;
}
if ( null !== $found )
{
$parts = explode( '/', trim( $route, '/' ) );
$before = array_slice( $parts, 0, $found, true );
var_dump( $before );
}