英文:
PHP read white space in file
问题
I int result = 2 * n;
result = result + 1;
II int result = n + 1;
result = result * 2;
III int result = (n + 1) * 2;
在读取和写入文件时,输出保持额外的空格以保持相同的间距是否有办法?
英文:
I have a file that looks like:
I int result = 2 * n;
result = result + 1;
II int result = n + 1;
result = result * 2;
III int result = (n + 1) * 2;
I read and write the file with:
while(!feof($myfile)) {
$line = fgets($myfile) ;
echo $line . "<br>";
}
the output I get is:
I int result = 2 * n;
result = result + 1;
II int result = n + 1;
result = result * 2;
III int result = (n + 1) * 2;
Is there a way to keep the extra spaces in the text to keep the spacing the same?
答案1
得分: 1
HTML无法保留多个空格,因此用&nbsp;
替换它们:
while(!feof($myfile)) {
$line = fgets($myfile) ;
echo str_replace(' ', '&nbsp;', $line) . "<br>";
}
英文:
HTML does not preserve multiple spaces, so replace them with &nbsp;
:
while(!feof($myfile)) {
$line = fgets($myfile) ;
echo str_replace(' ', '&nbsp;', $line) . "<br>";
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论