我有以下网址更换网址变量值
/index.php?option=com_zoo&task=item&item_id=292&Itemid=283
我想要做的一个变量来代替item_id
的价值是什么。我一直在检查几个php函数,如split
和parse_str
,但我不知道如何让它起作用。
我有以下网址更换网址变量值
/index.php?option=com_zoo&task=item&item_id=292&Itemid=283
我想要做的一个变量来代替item_id
的价值是什么。我一直在检查几个php函数,如split
和parse_str
,但我不知道如何让它起作用。
$url = '/index.php?option=com_zoo&task=item&item_id=292&Itemid=283';
$query = explode('?', $url); // Split the URL on `?` to get the query string
parse_str($query[1], $data); // Parse the query string into an array
echo $data['item_id']; // 292
$newValue = 300;
$data['item_id'] = $newValue; // Replace item_id's value
$url = $query[0].'?'.http_build_query($data); // rebuild URL
echo $url; // '/index.php?option=com_zoo&task=item&item_id=300&Itemid=283";
哇,多数民众赞成它,这是我想要的。谢谢 – lgt 2012-02-16 16:26:57
很高兴我能帮忙:-) – 2012-02-16 16:28:59
* 这是做*的确切方式
<?php
$url = '/index.php?option=com_zoo&task=item&item_id=292&Itemid=283';
$explodeData =parse_url($url);
$dataReplace = str_replace('item_id','replacedvariable',$explodeData['query'],$count);
$changedUrl = $explodeData['path']."?".$dataReplace;
echo $changedUrl;
?>
是这样的您为链接创建的网址?或者你是否在index.php中,并尝试使用item_id中的传递值? – Matt 2012-02-16 16:14:34
此URL是字符串还是当前URL(在地址栏中)? – 2012-02-16 16:14:52
这一个是当前的网址 – lgt 2012-02-16 16:16:29