简体   繁体   中英

PHP string replace tabs with spaces NOT using regex

How do I use str_replace to replace tabs with spaces in 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 . Try this:

$find = array("\t");
$replace = array(' ');
$string = str_replace($find,$replace,$string);

You have to use the \\t string. 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.

$find = array("\t"); //use \t here!
$replace = array(' ');
$string = str_replace($find,$replace,$string);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM