作为对API调用的响应,我正在获取完整的HTML脚本。完整意味着它包括HTML CSS和Javascript。现在,我将该HTML作为PHP变量中的字符串。
$content = '<html>
<head>
<script>--Some javascript and libraries included--</script>
<title></title>
</head>
<body>
<style>--Some Styling--</style>
</body>
</html>';
现在,在数据库中保存此变量的最佳方法是什么?如何?
或您想提出的其他建议(可能是序列化或打包)?
我使用base64编码的数据将BLOB数据类型存储在数据库中。样板代码如下。
$content = '<html>
<head>
<script>--Some javascript and libraries included--</script>
<title></title>
</head>
<body>
<style>--Some Styling--</style>
</body>
</html>';
在base64中编码数据
$encodedContent = base64_encode($content); // This will Encode
并使用BLOB将数据保存在数据库中。现在,在检索数据之后,只需按照以下说明对其进行解码即可。
$ContentDecoded = base64_decode($content); // decode the base64
现在,$ contentDecoded的值为纯HTML。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句