Hi!

I have some source code correctly indented and I need a regular expression that will replace the initial text spaces with  . I don't want to use a pre tag, just replace the leading spaces. For each line the expression should replace all space characters from the beginning to the end of the string until a character different from space is reached.

Any ideas?😕

    $string = [man]str_replace[/man](' ', ' ', $string);

    Easy as that...

    If you wanted to do tabs:
    $string = [man]str_replace[/man]("\t", '    ', $string);

      [man]strspn[/man] can tell you how many spaces the line starts with, and you can use that in [man]str_replace[/man].

      You could also use a regular expression, but the strspn/str_replace seems the less effort.

        You could also just change the style of whatever HTML element is containing the text to be "[noparse]white-space:pre[/noparse]".

          Weedpacket;10885968 wrote:

          [man]strspn[/man] can tell you how many spaces the line starts with, and you can use that in [man]str_replace[/man].

          You could also use a regular expression, but the strspn/str_replace seems the less effort.

          Thank you for your help, it works!

            Write a Reply...