如何移除多行大字符串左边的所有边距


how to remove all margins from left side of multi line big string?

我收到了一个大字符串,左边有很多空白(可能是不同大小的空白)!我当前的代码没有删除它?是否有办法删除所有这些空白为整个大字符串内容和所有开始行开始没有任何空白!

   $dataValue = $_POST['bigString'];
    $dataValue2 = preg_replace("/(^['r'n]*|['r'n]+)['s't]*['r'n]+/", "'n", $dataValue);

数据有这样的边距:

    #EXTM3U
    #EXTINF:-1, title1
    http://somesite.com/2.m3u8
    #EXTINF:-1, title2
    http://somesite.com/2.m3u8
    #EXTINF:0, title 3

,我想把字符串变成这样:

#EXTM3U
#EXTINF:-1, title1
http://somesite.com/2.m3u8
#EXTINF:-1, title2
http://somesite.com/2.m3u8
#EXTINF:0, title 3

您可以将此公认答案改编为使用ltrim:

$text = join(PHP_EOL, array_map("ltrim", explode(PHP_EOL, $text)));