http://www.mywebsite/product-tag/animal/
如何在没有反斜杠的情况下以这样的大写字母呼应动物:
动物
$link = 'http://www.mywebsite/product-tag/animal/';
$parts = explode( '/', $link );
echo(strtoupper($parts[4]));
如果要自动搜索,则需要使用 preg_match。
<?php
$string = 'http://www.mywebsite/product-tag/animal/';
$urlparts = explode("/", $string);
$animal = ($string[strlen($string)-1] == '/'? $urlparts[count($urlparts)-2] : end($urlparts));
echo strtoupper($animal);
?>
其实我只是想通了
$r = $_SERVER['REQUEST_URI'];
$r = explode('/', $r);
$r = array_filter($r);
$r = array_merge($r, array());
$endofurl = $r[1];
echo $endofurl;