Twig: url_decode

I encoded the url parameter with the url_encode filter.

// app.request.query.get("date") output 01/04/2016

href="{{ path('page', {date: app.request.query.get("date")|url_encode}) }}">

which are displayed in the URL

date=01%252F04%252F2016

So, on the requested page with URL parameters

 {{ app.request.query.get("date") }}

mapping 01% 2F04% 2F2016, but I would like to have 04/01/2016

I tried using a raw filter and also made a branch extension:

<?php
namespace SE\AppBundle\Twig;

class htmlEntityDecodeExtension extends \Twig_Extension
{
    public function getFilters()
    {
        return array(
            new \Twig_SimpleFilter('html_entity_decode', array($this, 'htmlEntityDecode'))
        );
    }

    public function htmlEntityDecode($html)
    {
        $html = html_entity_decode($html);
        return $html;
    }

    public function getName()
    {
        return 'html_entity_decode_extension';
    }
}

But even so, it continues to display 01% 2F04% 2F2016

I get the same result in my controller method with:

echo html_entity_decode($request->query->get('date'));

What is the right way to do this?

UPDATE:

date is specified from input of type "text". No, this is a simple string with numbers and /.

+4
source share
1 answer

url- , , , .

01%252F04%252F2016 . PHP, , 01%2F04%2F2016, , urlencoded. urldecode. : .

:

{{ path('page', {date: app.request.query.get("date")}) }}

UPDATE

this :

// "/" and "?" can be left decoded for better user experience, see
// http://tools.ietf.org/html/rfc3986#section-3.4
$url .= '?'.(false === strpos($query, '%2F') ? $query : strtr($query, array('%2F' => '/')));

, / URL-.

+3

All Articles