开发者

Combing URL component variables into a full URL

开发者 https://www.devze.com 2023-02-28 00:17 出处:网络
I would like to combine the variables below as a new variable called $fullurl.They are components of a URL.The structure of the combined variable is shown under the variables below.How can I do this?

I would like to combine the variables below as a new variable called $fullurl. They are components of a URL. The structure of the combined variable is shown under the variables below. How can I do this?

$urlc = nytimes.com/business/finance/articles/2005/05/10/20100727stock-prices-declining.html
$submissiondate = 2005-07-27 2022:38:10
$submittor = mike17
$countcomments = 15
$dispurl = nytimes.com
$submission = News about A Topic
$submissionid = 125
$domainurl = http://www.domain.com/folder/subfolder/index.php?

The combined order:

http://www.domain.com/folder/subfolder/index.php?submission=News+about+A+Topic++&submissionid=125&url=nytimes.com/business/finance/articles/2005/05/10/20100727stock-prices-declining.html&countcomments=15&submittor=mike17&submissiondate=2005-07-27%2022:38:10&d开发者_JS百科ispurl=nytimes.com&subcheck=0


Easiest way to do it would be to put all of those into an array, and then use http_build_query.

So:

$params = array(
   'submittor' => 'mike17',
   'count_comments' => 15,
);

$query_string = http_build_query($params);

$fullurl = $domainurl . $query_string;

I left off some of your parameters for brevity.


If you use an array instead of separates variables, you can build the query string in this way:

$data = array(
          'foo'=>'bar',
          'baz'=>'boom',
          'cow'=>'milk',
       );

$query_string = http_build_query($data);
0

精彩评论

暂无评论...
验证码 换一张
取 消