Double quotes in URL

1

I'm using the

<button class="button button1" value="janeiro" 
  onclick="location.href=
   'escolha_dia.php?inst=<?=$acao;?>&sala=<?=$acao2;?>&ano=<?=$acao3;?>&mes=janeiro';">
Janeiro</button>

but the result is double-quoted ":

http://localhost/teste/confirmar.php?inst=ufruralrj"&sala=ichs_paulo_freire"&ano=2016"&mes=janeiro"

How do I get this out?

    
asked by anonymous 07.04.2016 / 01:15

2 answers

2

I assume you came from this answer to another question from you:

  

link

In the original post (duly corrected by @rodorgas) quotes were missing in the value , and as a consequence, the end quotes became part of the value.

<input name="inst" value=<?=$acao;?>">
                         ^-- aqui faltou abrir aspas

Try this:

<input name="inst" value="<?=$acao;?>">

In fact, the ideal even is this:

<input name="inst" value="<?php echo htmlentities( $acao );?>">

This ensures that special characters will be properly handled, avoiding conflict with HTML.

    
07.04.2016 / 01:52
1

Apparently the values are already being double-quoted, which is strange. The ideal would be to investigate this, but if you just want to treat it the way it came, you can do it like this:

<?php
$acao = 'ufruralrj"';
$acao2 = 'ichs_paulo_freire"';
$acao3 = '2016"';


foreach ($$vars = array(&$acao, &$acao2, &$acao3) as &$var) {
    $var = rtrim($var, '"');
}

echo ("
    <button class=\"button button1\" value=\"janeiro\"
            onclick=\"location.href=escolha_dia.php?inst=$acao&sala=$acao2&ano=$acao3&mes=janeiro\">
        Janeiro
    </button>
    \n");
?>
    
07.04.2016 / 01:53