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条)

报告相同问题?

悬赏问题

  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的