php - 如何使用 file_put_contents 解析成 txt 文件
问题描述
我正在尝试使用 txt 文件中的输入字段解析空格,file_put_contents
但使用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>
例如,如果我首先在输入中输入一个空格,然后在文本之后,test
我的 txt 文件如下所示:
test
它应该是
test
我怎样才能做到这一点?
解决方案
如果它只是关于空格,你可以把它替换为str_replace
推荐阅读
- php - 当 woocommerce 产品具有属性或具有属性值时显示图像
- c# - 在 C# 中使用 SoapEnvelope 序列化为 XML
- signals - 奈奎斯特率和奈奎斯特频率有什么区别?
- ffmpeg - FFMPEG & YouTube Live - “Bad Video Settings” - 请使用 4 秒或更短的关键帧频率
- regex - 如何在过滤器pyspark RDD中过滤掉某种模式
- sql - FROM 子句中的大查询连接字符串
- ruby-on-rails - Heroku Release Phase 配置变量在变量名中带有点
- docker - Docker端口冲突,即使没有绑定端口
- css - 全屏打印 MaterialUI 对话框
- gltf - 文件glTF中的角度单位是什么?