使用base64_encode()和内爆来编码值


Encoding values using base64_encode() together with implode

所以我正在制作一个应用程序,其中用户从选择框中选择多个值并提交这些值。在后端,这些值需要在经过解码的URL中使用。假设,如果值是:-

Business
Study
Finance

而不是像file。php?cat=Business|Study|Finance,我想要使用(base64_encode)对这些类别进行编码,然后用分隔符|分隔。

我写了这个,但这并不能解决我的问题。

file.php?cat=<?php echo base64_encode(implode("|", $cat)); ?>

其中$cat是我从选择框中接收选择的数组。我该怎么做才能让它像我想要的那样工作呢?

<?php
$encodedCats = array();
foreach($cat AS $val){
  $encodedCats[] = base64_encode($val);
}
?>
file.php?cat=<?php echo implode("|", $encodedCats); ?>

try

<?php $arr = array('Business','Study','Finance');?>
<a href="clone.php?cat=<?php echo base64_encode(implode("|", $arr)); ?>">click</a> 

For get values

$decode = base64_decode($_GET['cat']);
$arr = explode('|', $decode);
print_r($arr); //Array ( [0] => Business [1] => Study [2] => Finance )