I am able to remove all single tabs from a string:
// Copying and pasting the tab directly
$txt = str_replace(" ", "", $txt);
This only removes single tabs, but not double tabs. I then tried this, thinking that "\t" would be sufficient to find the tabs:
$txt = preg_replace('/\t/', '', $txt);
However, it didn't work. Can anyone offer something better?
preg_replace('/\t+/', '', $string)
..| |
(tab) character but| |
(4 spaces) characters were supplied in the example code. Since the source$txt
value that was causing the issue was not provided, we can't verify the issue. The original code would have removed double tabs as 8 spaces as well, so seems OP may be wanting something likepreg_replace('/\t| {4}/', '', $txt);
to replace either tab or 4 spaces together, the+
is not needed unless start^
or end$
of pattern is also used.