[英]PHP string replace tabs with spaces NOT using regex
How do I use str_replace
to replace tabs with spaces in PHP? 如何使用
str_replace
用PHP中的空格替换制表符? I need to do so without using regular expressions. 我需要不使用正则表达式。
$find = array('');//use what here?
$replace = array(' ');
$string = str_replace($find,$replace,$string);
尝试-
$string = str_replace("\t", " ", $string);
The escape sequence for a tab character in PHP (as it is in many other languages) is \\t
. PHP中的制表符(与许多其他语言一样)的转义序列为
\\t
。 Try this: 尝试这个:
$find = array("\t");
$replace = array(' ');
$string = str_replace($find,$replace,$string);
You have to use the \\t
string. 您必须使用
\\t
字符串。 Usually you can use these special control characters with the backslash, such as \\n
for "line feed", \\r
for "carriage return", etc. This is true for most of the common programming languages. 通常你可以使用用反斜杠这些特殊的控制字符,如
\\n
为“换行”, \\r
为“回车”等,这是真正为大多数常见的编程语言。
$find = array("\t"); //use \t here!
$replace = array(' ');
$string = str_replace($find,$replace,$string);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.