单引号和双引号在文本字段,如何使他们可见


Single and double quotes in textfield, how to make them visible?

如何使单引号和双引号在文本字段中可见?从数据库中检索数据。例如:

//PHP code
$sor = mysqli_fetch_assoc($eredmeny);
$string = $sor['this_is_a_string_with_qoutes'];
//HTML with PHP
<input type="text" name="1" id="1" value="<?php echo $string?>">

但是如果字符串有双引号,整个字符串将不会显示在文本字段中,只显示第一个引号之前的部分。我的意思是,如果字符串是BANANA"RAMA它只会显示BANANA

你知道怎么解决这个问题吗?

printf('<input type="text" name="1" id="1" value="%s">',
       htmlspecialchars($string));

HTML转义数据。实际上,所有数据都输出到HTML中。