John Davidson

php - how to parse   into txt file with file_put_contents


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.

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>

per example if i first type a space in the input and after the text test
my txt file looks like this:


and it should be


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:

// 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

5 of 5 based on 5132 votes


© 2024 - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us