PHP字符串加引号,输出到html表格扭曲布局

PHP字符串加引号,输出到html表格扭曲布局,php,html,database,string,html-table,Php,Html,Database,String,Html Table,我正在用PHP编写一个评论脚本。审阅者编写的审阅文本与其他值(如日期和审阅者对审阅的标题)一起插入到数据库中 我想在一个单独的页面上的表格上输出评论。我已经写过了,它工作得很好,除了当评论员写类似“test”的东西时。因此,如果评论中有引号或语音标记,则表格会扭曲,评论会停留在一行上,并且不会跟随 代码如下: <?php echo "<tr $class>"; echo "<td width='400' class='style

我正在用PHP编写一个评论脚本。审阅者编写的审阅文本与其他值(如日期和审阅者对审阅的标题)一起插入到数据库中

我想在一个单独的页面上的表格上输出评论。我已经写过了,它工作得很好,除了当评论员写类似“test”的东西时。因此,如果评论中有引号或语音标记,则表格会扭曲,评论会停留在一行上,并且不会跟随

代码如下:

    <?php


        echo "<tr $class>";
        echo "<td width='400' class='style1' style='color: #069; font-size: 15px;'>".$rating." &nbsp;&nbsp;&ldquo;".$row['title']."&rdquo; &nbsp;</td>";
        echo "<td width='200' class='style1'><div align='left'>Reviewed ".date_format($timeCreate, 'j F Y ')."</div></td>";
        echo "</tr>";
        echo "<tr $class>";
        echo "<td width='200'>";

        // Prints pros, cons, and other thoughts fields
        if($row['comment'])
        {

                echo "<p class='style2'>".$row['comment']."</p><div id='usname'>by ".$row['name']."<br><br></div><div class='$g'><font size='2' color='black'>Was this review helpful?</font>&nbsp;<input type='submit' value='Yes' onClick = 'myCall()' style='background-color:#556B2F;color:white;padding:2px; cursor:pointer' name='help' id='$g' class='button' /></div></td><td><img src='Themes/images/glyphicons_072_bookmark.png' width='10' height='15'></div><font size='1' style='padding-bottom:10px;'>&nbsp;&nbsp;".$row['helpful']." found this helpful</font><div id='mybox'>

        </div></td>";
            echo '

    '; 
        }
        echo "</tr><tr><td colspan='2'><hr></td></tr>";


        echo "<tr $class>";

        $id = $row['id'];
        echo "</tr>";

    }

    echo ""; 
    echo "</table>";
}
else
{
    echo "<p class='red'>Error</p>";
    echo "<p>This person does not exist.</p>";
}
?>

也许你应该使用addslashes()


如果要显示文本,则稍后在显示它之前,需要将特殊字符转换为html实体

这将转换为
&和“至


如果需要转换单引号,请使用ENT_quotes选项。

我在下面的代码片段中看到了问题

echo "<td width='200'>";
        // Prints pros, cons, and other thoughts fields
        if($row['comment'])
        {

                echo "<p class='style2'>".$row['comment']."</p><div id='usname'>by ".$row['name']."<br><br></div><div class='$g'><font size='2' color='black'>Was this review helpful?</font>&nbsp;<input type='submit' value='Yes' onClick = 'myCall()' style='background-color:#556B2F;color:white;padding:2px; cursor:pointer' name='help' id='$g' class='button' /></div></td><td><img src='Themes/images/glyphicons_072_bookmark.png' width='10' height='15'></div><font size='1' style='padding-bottom:10px;'>&nbsp;&nbsp;".$row['helpful']." found this helpful</font><div id='mybox'>

        </div></td>";
            echo '

    '; 
        }
        echo "</tr><tr><td colspan='2'><hr></td></tr>";
echo”“;
//打印优点、缺点和其他想法字段
如果($row['comment']))
{
echo“

”$row['comment']”。

作者“$row['name']”。“

此评论有用吗?”。$row['help']”发现此评论有用 "; 回声' '; } 回声“
”;
如果设置了注释,那么您将添加两列,但如果未设置注释,那么它将打开一个TD,然后关闭TR。这可能会导致未格式化HTML。您可以添加一个其他条件并检查,如下面所示吗

echo "<td width='200'>";

        // Prints pros, cons, and other thoughts fields
        if($row['comment'])
        {

                echo "<p class='style2'>".$row['comment']."</p><div id='usname'>by ".$row['name']."<br><br></div><div class='$g'><font size='2' color='black'>Was this review helpful?</font>&nbsp;<input type='submit' value='Yes' onClick = 'myCall()' style='background-color:#556B2F;color:white;padding:2px; cursor:pointer' name='help' id='$g' class='button' /></div></td><td><img src='Themes/images/glyphicons_072_bookmark.png' width='10' height='15'></div><font size='1' style='padding-bottom:10px;'>&nbsp;&nbsp;".$row['helpful']." found this helpful</font><div id='mybox'>

        </div></td>";
            echo '

    '; 
        }
        else
        {
             echo "</td><td>&nbsp;</td>";
        }
        echo "</tr><tr><td colspan='2'><hr></td></tr>";
echo”“;
//打印优点、缺点和其他想法字段
如果($row['comment']))
{
echo“

”$row['comment']”。

作者“$row['name']”。“

此评论有用吗?”。$row['help']”发现此评论有用 "; 回声' '; } 其他的 { 回声“; } 回声“
”;
您能举例说明这个问题吗?截图就好了。最好是一个指向该问题的现场演示的链接。请将结果发布到表格中断的位置。您应该为宽度、高度和边框等指定
px
。例如,
400px
表格在
echo“

”$row['comment']处中断。“

这到底有什么帮助?还是会遇到同样的问题。我这样做了:
$com=$row['comment']$com1=htmlentities($com,ENT_报价);echo“

$com1

我看没有问题,谢谢你的帮助,但这仍然不起作用。我不需要if语句,有没有办法不用if语句解决它?
echo "<td width='200'>";

        // Prints pros, cons, and other thoughts fields
        if($row['comment'])
        {

                echo "<p class='style2'>".$row['comment']."</p><div id='usname'>by ".$row['name']."<br><br></div><div class='$g'><font size='2' color='black'>Was this review helpful?</font>&nbsp;<input type='submit' value='Yes' onClick = 'myCall()' style='background-color:#556B2F;color:white;padding:2px; cursor:pointer' name='help' id='$g' class='button' /></div></td><td><img src='Themes/images/glyphicons_072_bookmark.png' width='10' height='15'></div><font size='1' style='padding-bottom:10px;'>&nbsp;&nbsp;".$row['helpful']." found this helpful</font><div id='mybox'>

        </div></td>";
            echo '

    '; 
        }
        else
        {
             echo "</td><td>&nbsp;</td>";
        }
        echo "</tr><tr><td colspan='2'><hr></td></tr>";