没有反斜杠的url的echo结束

时间:2013-08-22 06:39:00

标签: php echo explode

http://www.mywebsite/product-tag/animal/

如何在没有反斜杠的情况下回应动物并且像这样的大帽子:

动物

3 个答案:

答案 0 :(得分:0)

$link = 'http://www.mywebsite/product-tag/animal/';
$parts = explode( '/', $link );
echo(strtoupper($parts[4]));

如果您想自动搜索,则需要使用preg_match。

答案 1 :(得分:0)

<?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);
?>

答案 2 :(得分:0)

实际上我只想出来了

$r = $_SERVER['REQUEST_URI']; 
$r = explode('/', $r);
$r = array_filter($r);
$r = array_merge($r, array()); 

$endofurl = $r[1];
echo $endofurl;
相关问题