Hi,

I could really use assistance, as I am now pulling my hair out over the following problem.

I am writing a CMS in PHP, that copies code from a textarea, on submission to a textfile, however I need to remove the formatting, ie newlines (most importantly), and the indents (if at all possible).

Basically I need to get code from this,

<H1>
Hello
</H1>
<P>
Some Text
</P>

to this,

<H1>Hello</H1><P>Some Text</P>

Any help really will be much appreciated. 🙂

Thanks

FiSH

    I assume that your html code is in a string, so here goes:

    $string = str_replace("\n","",$string);

    $string = str_replace("\t","",$string);

    I'm not sure about that second one, but I think that \t identifies tabs

      Originally posted by ereptur
      I assume that your html code is in a string, so here goes:

      $string = str_replace("\n","",$string);

      $string = str_replace("\t","",$string);

      I'm not sure about that second one, but I think that \t identifies tabs

      Let me explain what this is, for your future reference. What str_replace() does is replaces all givin instances of something with something else. So...

      str_replace("\n", "Hello", $string);

      would replace all enters(since \n stands for new line) with Hello. $string is the string it will do this too. So replacing "Hello" with "" will replace it with noting, which is the same as removing it. It works the same with tabs, or \t. What you could also do is replace all enters with <br>, and that would display the enters as breaks to a new line, but you don't have to.

        Write a Reply...