打印变量,包含单个和维度引用,作为输入元素值

I have $variable which contains single and dimensional quotes, like this a's"d

I want write this variable as value of checkbox element

<input type="checkbox" name="names[]" value="<?php echo $variable; ?>" />

but when I see result after send html forms, value from checkbox is not correct (reason is quotes), what is right way, for write variables like this, as input value?

use htmlentities with ENT_QUOTES

<?php echo(htmlentities($variable, ENT_QUOTES | ENT_HTML401)); ?>

You can escape the dimensional quotes :

<input type="checkbox" name="names[]" value="<?php echo str_replace('"','\\"',$variable); ?>" />

Or you can use htmlspecialchars() http://php.net/manual/en/function.htmlspecialchars.php

You want to encode your charachters to html elements so they do not break the string. Try something like this

$variable = htmlentities($variable);
<input type="checkbox" name="names[]" value="<?php echo $variable; ?>" />

The spec is written here http://php.net/manual/en/function.htmlentities.php if you need more info