1

我有这个html string

<p><span style="color: #4f4f4f; font-family: Arial; font-size: 12px; font-style: normal; 
font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 
15.600000381469727px; orphans: 2; text-align: -webkit-left; text-indent: 0px; text-transform:
 none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -
webkit-text-stroke-width: 0px; background-color: #ffffff; display: inline !important; float: 
none;">Numerical estimation is key in many craft and technical jobs where the ability to 
quickly and accurately estimate material quantities is essential. The speed at which you can 
answer these questions is the critical measure, as most people could achieve a very high sco
re given unlimited time in which to answer. You can therefore expect 25-35 questions in 10 
minutes or so.</span></p>

我想将其存储在我的 中database,但在执行查询时应用程序崩溃了。知道我是否应该删除任何特定symbol或任何东西,还是因为它的长度?

4

2 回答 2

4

通常,您应该执行SQL Escape操作。

于 2013-04-03T11:49:49.120 回答
2

只要你将它作为一个字符串插入它应该可以工作..试试这个:

    $htmlString = '<p><span style="color: #4f4f4f; font-family: Arial; font-size: 12px; font-style: normal; 
    font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 
    15.600000381469727px; orphans: 2; text-align: -webkit-left; text-indent: 0px; text-transform:
     none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -
    webkit-text-stroke-width: 0px; background-color: #ffffff; display: inline !important; float: 
    none;">Numerical estimation is key in many craft and technical jobs where the ability to 
    quickly and accurately estimate material quantities is essential. The speed at which you can 
    answer these questions is the critical measure, as most people could achieve a very high sco
    re given unlimited time in which to answer. You can therefore expect 25-35 questions in 10 
    minutes or so.</span></p>';

我基本上用替换了""''因为你的字符串已经包含双引号并且会中断。

SQL Escapes正如 Ismet Alkan 所说,在插入数据时执行始终是一种好习惯。

还要确保您的database列与字符串兼容,因此将类型设置为TEXT应该可以解决问题。

于 2013-04-03T11:55:22.100 回答