Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,855 questions

51,776 answers

573 users

How to remove (strip) whitespaces (space, tab, new line, carriage return) (\t, \n, \r) from a string in PHP

5 Answers

0 votes
$s = "    I'm a \nC/PHP\0/Java\r/C#/VB \tprogrammer \n   ";
$s1 = trim($s, " \r\n\0\t"); 
echo $s1 . "<br />";

/*
run: 

I'm a C/PHP/Java /C#/VB programmer

*/

 



answered Jul 4, 2016 by avibootz
0 votes
$s = "    I'm a \nC/PHP\0/Java\r/C#/VB \tprogrammer \n   ";
$s1 = ltrim($s); 
echo $s1 . "<br />";

/*
run: 

I'm a C/PHP/Java /C#/VB programmer 

*/

 



answered Jul 4, 2016 by avibootz
0 votes
$s = "    \t\twords words words  ...  ";
$t = ltrim($s); 
var_dump($t);

/*
run: 

string(24) "words words words ... " 

*/

 



answered Jul 4, 2016 by avibootz
0 votes
// "\n" (ASCII 10 (0x0A)) - new line (line feed)
// "\t" (ASCII 9 (0x09)) - tab

$s = "    \x09PHP string\x0A   ";
$t = trim($s); 
var_dump($t);

/*
run: 

string(10) "PHP string" 

*/

 



answered Jul 4, 2016 by avibootz
0 votes
// "\n" (ASCII 10 (0x0A)) - new line (line feed)
// "\t" (ASCII 9 (0x09)) - tab

$s = "    \x09PHP string\x0A   ";
$t = trim($s, " \t."); 
var_dump($t);

/*
run: 

string(11) "PHP string " 

*/

 



answered Jul 4, 2016 by avibootz

Related questions

...