Reputation: 812
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?
Upvotes: 38
Views: 85728
Reputation: 90
$string = trim(preg_replace('/\t/', '', $string));
This works for me. Remove the g
of @Mr. Aliens answer.
Upvotes: 3
Reputation: 1241
trim(preg_replace('/[\t|\s{2,}]/', '', $result))
Removes all tabs, including tabs created with multiple spaces
Upvotes: 3
Reputation: 2565
this will remove all tabs in your variable $string
preg_replace('/\s+/', '', $string);
Upvotes: 8
Reputation: 157334
Try using this regular expression
$string = trim(preg_replace('/\t/g', '', $string));
This will trim out all tabs from the string ...
Upvotes: 11