0

i received a big string that has lots of margin in the left side(probably different sizes of margins) ! My current code doesn't remove it ? is there away to remove all those margins for entire bigstring content and all start lines start without any margin!

   $dataValue = $_POST['bigString'];

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

the data has this type of margin:

    #EXTM3U

    #EXTINF:-1, title1
    http://somesite.com/2.m3u8

    #EXTINF:-1, title2
    http://somesite.com/2.m3u8

    #EXTINF:0, title 3

and i want to the the string to be like this:

#EXTM3U

#EXTINF:-1, title1
http://somesite.com/2.m3u8

#EXTINF:-1, title2
http://somesite.com/2.m3u8

#EXTINF:0, title 3
user1788736
  • 2,727
  • 20
  • 66
  • 110
  • 2
    possible duplicate of [How do you trim white space on beginning and the end of each new line with PHP or regex](http://stackoverflow.com/questions/7335060/how-do-you-trim-white-space-on-beginning-and-the-end-of-each-new-line-with-php-o) – NDM Sep 18 '15 at 15:35

1 Answers1

3

You can adapt this accepted answer to use ltrim:

$text = join(PHP_EOL, array_map("ltrim", explode(PHP_EOL, $text)));
Community
  • 1
  • 1
NDM
  • 6,731
  • 3
  • 39
  • 52