wordpress mysqli_fetch_array在结果中未显示单引号



当我得到结果时,单引号会作为特殊字符出现(问号?)有办法让它们正确显示吗?这是我的代码:

while($row = mysqli_fetch_array($result)){
    $category1 = $row['category'];
    $quer = "Select * from categories where id = $category1";
    $result1 = mysqli_query($con,$quer) or die ("Unable to execute query: $quer <br>Reason: It broke here!" . mysql_error()); 
    $category = mysqli_fetch_array($result1);
    ?>
    <span Style="Font-size: 25px; "><?php print $category['name']?></span><br>
    <p><span class="headerLink">QUESTION</span><br>
    <div class="bodytext" align="justify"><?php print  $row['question']; ?></div></p>
    <p><span class="headerLink">ANSWER</span><br>
    <div class="bodytext" align="justify"><?php print $row['answer']; ?></div></p>
    <div align="center"><a href="#top" class="topLink">&bull;&nbsp; Top &nbsp;&bull;</a></div><br>
<?php
    } ?>

以下是您可以尝试的几种方法:

<head></head> 中设置文档字符集

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

并使用htmlentities

 <span Style="Font-size: 25px; "><?php echo htmlentities($category['name'])?></span>

您还应该使用$wpdb对象来筛选sql注入

最新更新