I have this cookie which indicates 2 items split by /:

cookie packs = 10=BATTLEFIELD 2 + 1=20.00/10=BATTLEFIELD 2 + 1=20.00
$packs = explode("/", rawurldecode($_COOKIE["packs"]));

I need to decode it with urldecode(), but when I do it I lose the + sign between BATTLEFIELD 2 and 1, how can I avoid this?

有帮助吗?

解决方案

Make use of rawurldecode(). You won't lose the +

<?php
echo rawurldecode('10=BATTLEFIELD 2 + 1=20.00/10=BATTLEFIELD 2 + 1=20.00');

OUTPUT:

10=BATTLEFIELD 2 + 1=20.00/10=BATTLEFIELD 2 + 1=20.00

EDIT : [Since you changed the question]

<?php

$cookie_packs = '10=BATTLEFIELD 2 + 1=20.00/10=BATTLEFIELD 2 + 1=20.00';
$packs = explode("/", rawurldecode($cookie_packs));
var_dump($packs);

array (size=2)
  0 => string '10=BATTLEFIELD 2 + 1=20.00' (length=26)
  1 => string '10=BATTLEFIELD 2 + 1=20.00' (length=26)
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top