簡體   English   中英

將參數傳遞到網址中間

[英]pass parameters into the middle of a url

好的,我有一個調用Web服務的URL,可以說該URL是:

http://url.com/products/[productid]?Lanaugae=english $ username = username&token = 1234

我正在做的是在一個函數內調用Web服務,從獲取中獲取產品ID並將其傳遞,然后觸發執行所有卷曲特性的函數。

麻煩的一點是productid在url的中間,我在全局中聲明了該位置,而curl則從另一個函數觸發。 我認為在.net中,您可以在[productid]處使用{0},然后在調用變量告訴它應在[productid]中輸入什么內容時,我可以在PHP中做類似的事情嗎?

因此,在我班級的頂部,我想:

$this->url = 'http://url.com/products/{0}?Lanaugae=engish$username=username&token=1234';

在我的函數中,我想做類似的事情:

$productid = $_GET["productid"];
$responseData = $this->curl_dat_thing($this->url, $productid);

...這可能/有意義嗎?

嘗試像這樣使用sprintf()

$this->url = 'http://url.com/products/%s?Lanaugae=engish$username=username&token=1234';

$productid = $_GET["productid"];
$responseData = $this->curl_dat_thing(sprintf($this->url, $productid));

我不確定curl_dat_thing()里面是什么,但是您應該這樣做:

$this->url = 'http://url.com/products/'.$productid.'?Lanaugae=engish&username=username&token=1234';

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM