English 中文(简体)
• 如何将多位划界员的“URL”插座改为“PHP”中的另一座插座?
原标题:How to convert URL string with multiple delimiters into another string in PHP?

因此,我有这一样本:

?items=3744130|1^356221|2^356222|1

摘自URL:

http://www.example.com/process.php?items=3744130|1^356221|2^356222|1

我需要把它变为现实,而对于我来说,我已经 st。

?items=model_1=3744130&qty_1=1&model_2=356221&qty_2=2&model_3=356222&qty_3=1

我 far开了这段话,但那是这样。

$url = substr($_SERVER[ QUERY_STRING ],6); 
$query = explode( ^ , $url); 
echo http_build_query($query,  model_ );

目前的产出是:

model_0=1234435%7C9&model_1=56788%7C9&model_2=6758765%7C9&model_3=3736543%7C9

我怎样才能把第一套编号改为model_1,而不是缺省代码?

增 编

问题回答

您在将其通过至<条码>之前需要用钥匙建立阵列。 如果你想要从1个开始。

$arr = array();
$count = 1;

foreach (explode( | , $_GET[ items ]) as $item) {
  $elements = explode( ^ , $item);
  if (count($elements) == 1) {
    $arr["model_$count"] = $elements[0];
    $arr["qty_$count"] = 1;
  }
  else {
    $arr["model_$count"] = $elements[1];
    $arr["qty_$count"] = $elements[0];
  }
  $count++;
}

$query = http_build_query($arr);

应当迅速派遣部队。

....
$url = substr($_SERVER[ QUERY_STRING ],6);
$query = explode( ^ , $url);

array_unshift($query, placeholder );
$result=http_build_query($query,  model_ );
$result = substr($result, 19);
....

为此:

$items = explode( ^ , $_GET[ items ]);
$query =   ;
foreach ($items as $key => $val) {
    list($model, $qty) = explode( | , $val);
    $query .=  &model_ .($key+1). = .urlencode($model);
    $query .=  &qty_ .($key+1). = .urlencode($qty);
}
echo substr($query, 1);




相关问题
URL rewrite in IIS6 - Third party tools

I have collected the following api/sdk/whatever which provide modules for doing url rewriting in IIS 5/6/7. Some are free-open source and some require $. I haven t tried any of them. I would like to ...

Rewrite spring-security redirect URLs

I m trying to get Tuckey UrlRewriteFilter to tidy up URLs for my webapp. One problem I ve got is that when spring-security notices that an anonymous user is trying to access a protected resource it ...

ASP.NET Friendly URLs

In my research, I found 2 ways to do them. Both required modifications to the Application_BeginRequest procedure in the Global.Asax, where you would run your code to do the actual URL mapping (mine ...

Could I get by HttpModule the URL that contains * before?

My web-site is working under ASP.NET 3.5, IIS7, Integrated pipiline mode. My HttpModule is getting request to all resources, including URLs like this: http://my-site.com/address And I would support *...

Domains & Foreward Slash

This is rather difficult to explain so please bear with me. We will be hosting 4 websites on our server and the plan is to have each site sit under its own domain: site-a.com site-b.com sub1.site-b....

URL Mod-Rewrite

I currently have a working URL: http://example.com/security-services.php?service=fixed-camera-surveillance and then I have PHP say, $_REQUEST[ service ] to do some stuff... But I d like to ...

热门标签