如何在不使用正则表达式的情况下从txt文件中删除 \ t?
Input: The input is read from a text file: while ($data = FGets($soubor)) { ... }
.
Output: I would like to safe content to DB (import) without
\t
.
I think, that it offers an alternative for trim:
while () ...
$editedText = trim($data, "\t");
I need \t, and check in whole txt document. Any suggestions and samples?
What is the best way for this easy task without RE?
输入 strong>:从文本文件中读取输入: 输出 strong>:我想安全内容到DB(导入)而不用 我认为,它为trim提供了另一种选择: p>
我需要\ t,
并检入 整个 strong> txt文档。 任何建议和样本? p>
没有RE strong>这项简单任务的最佳方法是什么? p>
div> while($ data = FGets($ soubor)){...} code>。 p>
\ t code>。 p>
while( )...
$ editedText = trim($ data,“\ t”);
code> pre>
The str_replace()
function is your new best friend.
$editedText = str_replace(array("\t", "
"), "", $data);
-
strtr
: http://www.php.net/manual/en/function.strtr.phpstrtr($s, array(""=>" ", " "=>" ", "\t"=>" "));
-
str_replace
: http://www.php.net/manual/en/function.str-replace.phpsee other answer
I use
s.trim();
it helps to lose whiteSpace, , \t and so on from both ends of the string.