dongzi3805 2012-01-23 12:15
浏览 14
已采纳

如何从网址获取价值?

If I have url like this: www.example.com/product/yellow-bed is it possible to retrieve product name from url? For example, if url would be like www.example.com?page=product&product_name=yellow_bed I would use:

$product = $_GET['page'];
$product_name = $_GET['product_name'];

But how to get it from www.example.com/product/yellow-bed ?

  • 写回答

6条回答 默认 最新

  • douhuan1257 2012-01-23 12:22
    关注

    Get the URI by "$_SERVER["REQUEST_URI"]". Convert the string into an array with explode:

    $uri = 'www.google.com/product/yellow-bed' //uri = $_SERVER["REQUEST_URI"]
    $uriArray = explode('/', $uri);
    $product = $urlArray[1];
    $product_name = $urlArray[2];
    

    0 = www.google.com, 1 = product, 2 = yellow-bed

    PHP manual: array explode ( string $delimiter , string $string [, int $limit ] ).

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(5条)

报告相同问题?