Jump to content

Indent problems with styling of HTML source code while using nl2br function...


cgm225

Recommended Posts

I have a string of text in a variable, let's say:

 

$text = "<a href='example.com'>Example.com</a>\n<a href='test.com'>Test.com</a>"; 

 

...and I echo the string with nl2br...

 

echo nl2br($text);

 

...which returns in my html source code as:

 

<a href='example.com'>Example.com</a><br />
<a href='test.com'>Test.com</a>

 

This is fine, but I am having the following problem when I use it as follows...

<html>
...snip...

     <a href='somelink.com'>somelink.com</a><br />
     <?php echo nl2br($text); ?>
     <a href='somelink.com'>Example.com</a><br />

...snip...
</html>

 

...because the nice indentation of the html source code is not preserved, and looks something like...

<html>
...snip...

     <a href='somelink.com'>somelink.com</a><br />
     <a href='example.com'>Example.com</a><br />
<a href='test.com'>Test.com</a>
     <a href='somelink.com'>Example.com</a><br />

...snip...
</html>

 

Here is my question... how do I get every new line created with the nl2br function to also get an indentation in the html source code?

 

Thanks in advance!

  • 3 weeks later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.