gpt4 book ai didi

php - 从字符串中提取参数

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:54:55 24 4
gpt4 key购买 nike

我必须像这样提取一个字符串:

index.php?module=Reports&action=abc&rname=Instantpayment

现在我的任务是在 PHP 中提取 reportactionrname 值。

我已经尝试使用 explode(),但我无法提取 module

我该怎么做?

最佳答案

在这种情况下,您可以使用 parse_str():

$string = 'index.php?module=Reports&action=abc&rname=Instantpayment';
$string = substr($string, strpos($string, '?')+1); // get the string from after the question mark until end of string
parse_str($string, $data); // use this function, stress free

echo '<pre>';
print_r($data);

应该输出:

Array
(
[module] => Reports
[action] => abc
[rname] => Instantpayment
)

关于php - 从字符串中提取参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26479999/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com