我有一个变量发布到另一个页面,当回显时,它看起来像
Acme, Upgrade Site, Kansas
我想用逗号分隔它们并分配 3 个变量,例如
$Company = ‘Acme’;
$Action = ‘Upgrade Site’;
$Location = ‘Kansas’;”
我有一个变量发布到另一个页面,当回显时,它看起来像
Acme, Upgrade Site, Kansas
我想用逗号分隔它们并分配 3 个变量,例如
$Company = ‘Acme’;
$Action = ‘Upgrade Site’;
$Location = ‘Kansas’;”
$str= 'Acme, Upgrade Site, Kansas' ;
$arr = explode(',',$str);
$Company = $arr[0];
$Action = $arr[1];
$Location = $arr[2];
尝试
所以我认为最好的选择可能是使用explode
:
// Assume $inputString is your input
$explodedInput = explode(",", $inputString);
// Now, $explodedInput[0] will be Company,
// $explodedInput[1] will be "Upgrade Site", etc...
$Company = $explodedInput[0] //...