从php中的STRING url获取变量 [英] getting variables from STRING url in php

查看:28
本文介绍了从php中的STRING url获取变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有一个看起来像这样的网址,那么读取值的最佳方法是什么

If I have a url that looks like this, what's the best way to read the value

http://www.domain.com/compute?value=2838

我试过 parse_url() 但它给了我 value=2838 而不是 2838

I tried parse_url() but it gives me value=2838 not 2838

请注意,我说的是字符串,而不是实际的网址.我将网址存储在一个字符串中.

please note I'm talking about a string, not an actual url. I have the url stored in a string.

推荐答案

您可以在查询中使用 parse_urlparse_str.

You can use parse_url and then parse_str on the query.

<?php
$url = "http://www.domain.com/compute?value=2838";
$query = parse_url($url, PHP_URL_QUERY);
$vars = array();
parse_str($query, $vars);
print_r($vars);
?>

打印:

Array
(
    [value] => 2838
)

这篇关于从php中的STRING url获取变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆