I have my file php file_put_contents so;
file_put_contents($file, $data . "\n", FILE_APPEND|LOCK_EX);
when it write to my File test.txt , the output is with number of bytes that were written on the file .
a:4:{s:4:"name";s:4:"aaaa";s:5:"email";s:10:"aaa@gmx.de";s:7:"message";s:27:"mm";s:8:"datetime";s:22:"11/10/2018 05:20:35 pm";}
I will that it ONLY write the data WITHOUT bytes number , can please anyone help me , thanks !
my Code;
<?php
header('Content-Type: text/html; Charset=utf-8');
mb_internal_encoding('UTF-8');
date_default_timezone_set('Europe/Berlin');
error_reporting(E_ALL);
class ClassProveContakt3
{
private $Name;
private $Email;
private $Message;
private $PostOK;
private $DateTime;
private $items;
function __construct()
{
$this -> DateTime = date('m/d/Y h:i:s a');
$this -> items = ['Name', 'Email', 'Message'];
$flag = true;
foreach ( $this -> items as $key ) {
if ( empty ( $_POST[$key] ) ) {
$flag = false;
} else {
$this -> $key = trim( filter_var( $_POST[$key], FILTER_SANITIZE_STRING ) );
}
}
$this -> PostOk = $flag;
}
function ShowForm()
{
?>
<form method="POST">
<label for="name">Name </label>
<input type="text" id="name" name="Name" value="<?= $this->Name ?>">
<label for="email">E-mail </label>
<input type="email" id="email" name="Email" value="<?= $this->Email
?>">
<br><br>
<label> Message: <br>
<textarea cols="45" rows="6" name="Message"><?= $this->Message ?></textarea>
</label>
<br><br>
<input type="submit" name="post" value="POST COMMENT" id="comment">
</form>
<?php
}
function PostOkT()
{
if ($this -> PostOK)
{
return;
}
if (empty($this->Name) || empty($this->Email) || empty($this->Message))
{
echo "<br>" . "<b>" . "<h3>*** Please enter all required fields ***</h3>" . "</b>";
}
else
{
$file = "test.txt";
$datetime = date('m/d/Y h:i:s a', time());
$data = array("name" => $this->Name, "email" => $this->Email, "message" => $this->Message, "datetime" => $datetime);
$data = serialize($data);
file_put_contents($file, $data . "\n", FILE_APPEND|LOCK_EX);
$messages = file($file);
foreach ($messages as $value) {
$data = unserialize($value);
echo "<br>"
. "<b>From: </b>" . htmlspecialchars( $data["name"])
. "<b> at: </b>" . htmlspecialchars( $data["datetime"])
. "<br><br>" . htmlspecialchars( $data["email"])
. "<br><br>" . htmlspecialchars( $data["message"])
. "<br><hr>";
}
}
}
}
?>