PHP - Remove all tabs from string

前端 未结 5 1517
生来不讨喜
生来不讨喜 2021-02-01 03:21

I am able to remove all single tabs from a string:

// Copying and pasting the tab directly
$txt = str_replace(\"    \", \"\", $txt); 

This only

相关标签:
5条回答
  • 2021-02-01 03:38
    trim(preg_replace('/\t+/', '', $string))
    
    0 讨论(0)
  • 2021-02-01 03:44

    Try using this regular expression

    $string = trim(preg_replace('/\t/g', '', $string));
    

    This will trim out all tabs from the string ...

    0 讨论(0)
  • 2021-02-01 03:45
    trim(preg_replace('/[\t|\s{2,}]/', '', $result))
    

    Removes all tabs, including tabs created with multiple spaces

    0 讨论(0)
  • 2021-02-01 03:51

    this will remove all tabs in your variable $string

    preg_replace('/\s+/', '', $string);
    
    0 讨论(0)
  • 2021-02-01 03:58

    $string = trim(preg_replace('/\t/', '', $string));

    This works for me. Remove the g of @Mr. Aliens answer.

    0 讨论(0)
提交回复
热议问题