PHP strpos问题

I visit my page www.mysite.com/theme/test/index.php which contains the code below. I expect to see the word test inside the h1 but it is blank :-( Can someone explain where I've gont wrong?

<?php
$url = 'http://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];

if ((false !== strpos($url,'theme')) || (false !== strpos($url,'colours'))) {

    if(preg_match("/\/(\d+)$/",$url,$matches)) { $end=$matches[1]; }
    ?>
    <div class="row">
        <div class="medium-12 columns">
            <h1 class="page-title"><?php echo ucwords(str_replace("-"," ",$end)); ?></h1>
        </div>
    </div>
<?php
}
?>

Thank you

I think your preg_match is wrong. \d means digit. You don't have any in your url.

I'm not really sure exactly what information you have going through your script when it is being run, but my best guess is that $end is never being set.

Check to make sure that your regular expression matches, otherwise $end will be empty.

Resolved.

@Marcin was right.

$end = end((explode('/', rtrim($url, '/'))));

Found this useful: Get Last Part of URL PHP