通过特殊字符的输入值复选框

问题描述 投票:-3回答:1

我需要一个复选框字段的值内通过特殊字符。

特殊字符是:

Più 
m<sup>2</sup>

这相当于字

Più
m raised to 2

我这样做,但我不知道这是否是正确的:

<input type="radio" class="custom-control-input pradio" name="p8" id="p8_1" 
value="<?php echo htmlspecialchars($stringadomanda8, ENT_QUOTES, 'UTF-8') ?> 
di 60m<?php echo htmlspecialchars($iniziometroquadro)?>2<?php echo 
htmlspecialchars($finemetroquadro, ENT_QUOTES, 'UTF-8')?>">

该预期值,使文件

    $p8 = [
    'Pi&ugrave; di 60m<sup>2</sup>' => 1.00,
    'Da 51 a 60m<sup>2</sup>' => 0.95,
    'Da 41 a 50m<sup>2</sup>' => 0.90,
    'Fino a 40m<sup>2</sup>' => 0.85,
    'Piscina prefabbricata fino a 40m<sup>2</sup>' => 0.77,
];

我想,以确保有特殊字符值正确服用。

如果我尝试打印echo htmlspecialchars($stringadomanda8, ENT_QUOTES, 'UTF-8')我得到Pi&ugrave;但不Più

php
1个回答
0
投票

这不是件好事,那些HTML元素作为另一个HTML元素的值,但是这是你问什么:

// encode string with htmlentities() when you load the form
$txt = 'Più m<sup>2</sup>';
$encoded = htmlentities($txt);

// decode it with html_entity_decode() when you have received the value
echo html_entity_decode($encoded);
© www.soinside.com 2019 - 2024. All rights reserved.