mysql批量上传数据时的转义问题

请教个关于sql的问题
就是我批量上传数据时(数据都是html),会发生错误,应该是有些地方需要转义。
但里面的html太多,也不知道什么地方需要转义,有没有其他办法?

update ecs_article set content='<div style="width: 700px" id="boxA">
<div style="width: 700px" id="pro_bot">
<h2 id="MCOA">Thymopoietin / TMPO Molecule Synonym Name</h2>
<p>Thymopoietin,TMPO,LAP2</p><h2 id="MCOA">Thymopoietin / TMPO Protein Products</h2>
<table width="600" cellspacing="0" cellpadding="0" class="tab01">
    <tbody>
        <tr>
            <td width="110" class="T_tit">Cat No</td>
            <td width="100" class="T_tit">Species</td>
            <td width="390" class="T_tit">Product Description</td>
        </tr><tr><td>TMO-H5129</td><td>Human</td><td><a href="http://www.acrobiosystems.com/P2150-Human-Thymopoietin--TMPO-Protein.html">Human Thymopoietin / TMPO Protein</a></td></tr></tr></tbody>
</table>
<br /><h2 id="MCOA">Thymopoietin / TMPO Molecule Background</h2>
<p style="width: 700px">Lamina-associated polypeptide 2, isoforms beta/gamma (LAP2) is also known as thymopoietin (TMPO), isoforms beta/gamma (TP beta/gamma). The thymopoetin (TMPO) gene encodes three alternatively spliced mRNAs encoding proteins of 75 kDa (alpha), 51 kDa (beta) and 39 kDa (gamma) which are ubiquitously expressed in all cells. TMPO may play a role in the assembly of the nuclear lamina, and thus help maintain the structural organization of the nuclear envelope. Also, TMPO may function as a receptor for the attachment of lamin filaments to the inner nuclear membrane. Furthermore, TMPO beta is a human homolog of the murine protein LAP2. Given the nuclear localization of the three TMPO isoforms, it is unlikely that these proteins play any role in CD90 induction.</p><h2 id="MCOA">Reference</h2><ul id="ul-bot"><li class="li-bot"><a target="new" href="http://www.ncbi.nlm.nih.gov/pubmed/18403046">(1) Shaklai S., et al., 2008, Eur. J. Cell Biol. 87:267-278.</a></li><li class="li-bot"><a target="new" href="http://www.ncbi.nlm.nih.gov/pubmed/12538639">(2) Martins S., et al., 2003, J. Cell Biol. 160:177-188.</a></li></ul><br />
<br />
&nbsp;</div>
</div>
<p>&nbsp;</p><p>&nbsp;</p>' where article_id="998";
阅读 2.4k
3 个回答

$content=<<<STR
<div style="width: 700px" id="boxA">
<div style="width: 700px" id="pro_bot">
<h2 id="MCOA">Thymopoietin / TMPO Molecule Synonym Name</h2>
<p>Thymopoietin,TMPO,LAP2</p><h2 id="MCOA">Thymopoietin / TMPO Protein Products</h2>
<table width="600" cellspacing="0" cellpadding="0" class="tab01">
    <tbody>
        <tr>
            <td width="110" class="T_tit">Cat No</td>
            <td width="100" class="T_tit">Species</td>
            <td width="390" class="T_tit">Product Description</td>
        </tr><tr><td>TMO-H5129</td><td>Human</td><td><a href="http://www.acrobiosystems.com/P2150-Human-Thymopoietin--TMPO-Protein.html">Human Thymopoietin / TMPO Protein</a></td></tr></tr></tbody>
</table>
<br /><h2 id="MCOA">Thymopoietin / TMPO Molecule Background</h2>
<p style="width: 700px">Lamina-associated polypeptide 2, isoforms beta/gamma (LAP2) is also known as thymopoietin (TMPO), isoforms beta/gamma (TP beta/gamma). The thymopoetin (TMPO) gene encodes three alternatively spliced mRNAs encoding proteins of 75 kDa (alpha), 51 kDa (beta) and 39 kDa (gamma) which are ubiquitously expressed in all cells. TMPO may play a role in the assembly of the nuclear lamina, and thus help maintain the structural organization of the nuclear envelope. Also, TMPO may function as a receptor for the attachment of lamin filaments to the inner nuclear membrane. Furthermore, TMPO beta is a human homolog of the murine protein LAP2. Given the nuclear localization of the three TMPO isoforms, it is unlikely that these proteins play any role in CD90 induction.</p><h2 id="MCOA">Reference</h2><ul id="ul-bot"><li class="li-bot"><a target="new" href="http://www.ncbi.nlm.nih.gov/pubmed/18403046">(1) Shaklai S., et al., 2008, Eur. J. Cell Biol. 87:267-278.</a></li><li class="li-bot"><a target="new" href="http://www.ncbi.nlm.nih.gov/pubmed/12538639">(2) Martins S., et al., 2003, J. Cell Biol. 160:177-188.</a></li></ul><br />
<br />
&nbsp;</div>
</div>
<p>&nbsp;</p><p>&nbsp;</p>
STR;
$sql = "update ecs_article set content='".$content."' where article_id='998'";
update ecs_article set content='html代码' where article_id='998'";

转行了需要 拼接

update ecs_article set content='<div style="width: 700px" id="boxA">'+
'<div style="width: 700px" id="pro_bot">' where article_id="998";

htmlspecialchars

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题