Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP - Remove all tabs from string

Tags:

php

tabs

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?

like image 866
Mark Avatar asked Jan 29 '13 16:01

Mark


People also ask

How to remove all spaces in string php?

The trim() function removes whitespace and other predefined characters from both sides of a string. Related functions: ltrim() - Removes whitespace or other predefined characters from the left side of a string.

How to remove extra spaces between words in php?

$str = "This text"; $str = preg_replace('/\\s/','',$str); echo $str; That would be a good method to use if you want to remove other characters, such a punctuation, from a string aswell. You would need to construct a regular expression mind you.

How to replace spaces in a string php?

Answer: Use the PHP str_replace() Function You can simply use the PHP str_replace() function to strip or remove all spaces inside a string.


1 Answers

trim(preg_replace('/\t+/', '', $string)) 
like image 87
Zamicol Avatar answered Oct 03 '22 00:10

Zamicol