我有一个关于用PHP写HTML文件的问题。
我有这个函数:
function openHTML ($file) {
if (file_exists($file)) {
$handle = fopen($file, "r");
$output = fread($handle, filesize($file));
fclose($handle);
return $output; // output file text
}else{
return "This file is not exists";
}
}
function saveHTML ($file,$string) {
$a = fopen($file, 'w');
fputs($a,stripslashes($string));
fclose($a);
return "success";
}当我使用openHTML时,这是很好的。但不幸的是,在我用openHTML()打开的文件中,有一些&,然后我用saveHTML()保存,但是字符串或代码保存在char &时停滞了。
示例:更新!
我用openHTML()打开空白的file.html,然后开始输入下面的字符串:
<html>
<head>
</head>
<body>
This is my login page & user page
</body>
</html>在我用代码saveHTML()保存之后
<html>
<head>
</head>
<body>
This is my login page最后找不到代码。在&停滞不前。
我用过fputs,utf8_encode,fwrite,file_put_contents。仍然没有解决。
发布于 2012-04-27 23:56:13
试一试
$output = htmlentities($output);在你要保存的字符串上。
check it out here
它会将所有HTML实体更改为其适用的字符。在这种情况下,您的&将更改为
&发布于 2012-04-27 23:48:28
在PCDATA节中,单独的和号无效。请改用&。
发布于 2012-04-27 23:52:41
尝试使用已安装fputs()的fwrite()
https://stackoverflow.com/questions/10353729
复制相似问题