如何使file_get_contents将转义序列识别为特殊字符


How to make file_get_contents recognize escape sequences as special characters?

我需要从文件中获取内容,以便将转义序列(如'n)识别为特殊字符。

考虑以下代码:

<?php
$f = file_get_contents("test.txt");
echo "$f";
?>

而test.txt只包含:

Test'nOnly

回显:

Test'nOnly

而我想有:

Test
Only

是否有一种方法来完成它与file_get_content或我应该使用其他东西(如输出缓冲)?

尝试使用printf,该函数输出一个格式化字符串。

<?php
$f = file_get_contents("test.txt");
printf ($f);
?>