Double quotes in the URL

Asked

Viewed 769 times

1

I’m using the remote

<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 coming with double quotes " :

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

How do I get it off?

  • 1

    Could you post the part of your PHP that is generating the variables used to compose the GET of the link? Because apparently these double quotes are coming from the end of each PHP variable and should not exist, either single or double. ** Puts the. :)

2 answers

2


I assume you came from this answer of another question of yours:

/a/121814/

In the original post (properly corrected by @rodorgas) quotes were missing on value, and as a result, the quotation marks at the end became part of the.

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

Try it like this:

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

Actually, the ideal thing is this:

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

This way you ensure that special characters are properly treated, avoiding conflict with HTML.

  • Ball show. Just changing value="<?php echo htmlentities( $acao );?>"> all the double quotes from the URL are gone. Thank you very much.

1

Apparently the values are already coming in double quotes, which is weird. The ideal would be to investigate it, but if you want to just treat it the way it came, you can do it this way:

<?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");
?>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.