这是我用来从 MYSQL 返回的数据在 PHP 中创建数组的代码:-foreach($empRecords->result_array() as $row) { $tid = $row['transaction_id']; $checkbox = '<input type="checkbox" name="check[]" value="'.$tid.'">'; $data[] = array( $checkbox, $row['transaction_id'], $row['member_id'], $row['member_name'], ); }我得到的结果是:-Array( [0] => Array ( [0] => <input type="checkbox" class="CheckedarrayCount" name="check[]" value="247"> [1] => 247 [2] => 101257 [3] => Nithin ) [1] => Array ( [0] => <input type="checkbox" class="CheckedarrayCount" name="check[]" value="249"> [1] => 249 [2] => 101258 [3] => Rekha ))但这就是我得到的结果:-{ "data": [ ["\u003Cinput type=\"checkbox\" class=\"CheckedarrayCount\" name=\"check[]\" value=\"247\"\u003E", "247", "101257", Nithin\u003C\/a\u003E", ], ["\u003Cinput type=\"checkbox\" class=\"CheckedarrayCount\" name=\"check[]\" value=\"249\"\u003E", "249", "101258", "ERekha\u003C\/a\u003E"],}请帮忙!
1 回答
尚方宝剑之说
TA贡献1788条经验 获得超4个赞
创建数组时,您应该在PHP中对 html 字符进行编码
使用htmlspecialchars
$checkbox = htmlspecialchars('<input type="checkbox" name="check[]" value="'.$tid.'">', ENT_QUOTES);
或使用htmlentities
$checkbox = htmlentities('<input type="checkbox" name="check[]" value="'.$tid.'">');
如果你想在解析返回的字符串时使用Javascript
<script> // console.log(decodeURIComponent(YOUR_STRING)) console.log(decodeURIComponent('\u003c')); </script>
- 1 回答
- 0 关注
- 69 浏览
添加回答
举报
0/150
提交
取消