I am trying to parse a space form an input field in a txt file with file_put_contents
but i do not succeed in it with htmlentities
.
<?php
if($_SERVER['REQUEST_METHOD'] == 'POST') {
if( isset($_POST['translation']) ) {
$translation = htmlentities($_POST['translation']);
$translation_input = $translation.PHP_EOL;
$translationfile = 'data/translations.txt';
file_put_contents($translationfile, $translation_input);
}
}
?>
<form action="<?php $_SERVER['PHP_SELF']; ?>" method="POST" role="form">
<input class="form-control" name="translation" type="text" value="" />
<button type="submit" name="submit" class="btn btn-primary w-100">UPDATE/TRANSLATE</button>
</form>
per example if i first type a space in the input and after the text test
my txt file looks like this:
test
and it should be
test
How can i achieve this?
My Answer:
To parse a PHP file, you can use the `parse_ini_file()` function. This function parses a configuration file and returns the settings in an associative array. Here's an example of how to use it:
php
// Load the configuration file
$config = parse_ini_file('config.ini');
// Access the settings in the configuration file
echo $config['username'];
echo $config['password'];
In this example, we are loading a configuration file called `config.ini` and accessing the settings in the file using the associative array returned by `parse_ini_file()`. You can then use these settings in your PHP code as needed.
Rate this post
3 of 5 based on 9268 votesComments