I have an issue about writing HTML file with PHP.
I have this function :
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";
}
When I’m using openHTML it’s fine. But unfortunately, in file that I opened with openHTML() there are some &, and then I’m saving with saveHTML() but then string or codes that save stalled at char &.
Example : UPDATE !
I open blank file.html with openHTML() and I start to type some string bellow :
<html>
<head>
</head>
<body>
This is my login page & user page
</body>
</html>
After I save with code saveHTML():
<html>
<head>
</head>
<body>
This is my login page
At last code to be missing. Stalled at &.
I have using fputs, utf8_encode, fwrite, file_put_contents. Still not solved.
try
on the string your going to save.
check it out here
It will change all HTML entities to their applicable charactors.
In this case your & will be changed to