Jump to content

nl2br()


dsjoes

Recommended Posts

i am using the below script that i got from the php manual but it is putting to many <br /> in.

 

script from php manual

<?php
      $string_text=file_get_contents("newsletter_files/newsletter.txt"); // load text file in var
      $new_text=nl2br($string_text); // convert CR & LF in <br> in newvar
      echo $new_text; // print out HTML formatted text
      unset($string_text, $new_text); // clear all vars to unload memory
?>

 

this is the source view

<div class="maintext"><center><h1>Newsletter</h1></center><br />
<br />
text here<br />

<br />
text here</div>

 

this is what i put in the text file

<center><h1>Newsletter</h1></center>

 

text here

 

text here

Link to comment
https://forums.phpfreaks.com/topic/230808-nl2br/
Share on other sites

this is the source view

<div class="maintext"><center><h1>Newsletter</h1></center><br />
<br />
text here<br />

<br />
text here</div>

 

sorry wrote wrong thing the script is making a really big gap between the title newsletter and the first line of text not all of the text it looks like 4-5 line spaces

Link to comment
https://forums.phpfreaks.com/topic/230808-nl2br/#findComment-1188186
Share on other sites

h1 has margin and padding around it anyway so that needs to be set to 0;

 

I think you have

h1 with margin & padding

<br /> break 1 with margin & padding, maybe, I can't remember

<br /> break 2 with margin & padding, maybe

text here  with margin & padding

<br /> with margin & padding

<br /> with margin & padding

text here  with margin & padding

</div>

 

Can you remove some breaks and playwith it ?

 

Also use Firefox's Firebug, it helps a lot and tells you what and where the margin & padding is

Link to comment
https://forums.phpfreaks.com/topic/230808-nl2br/#findComment-1188196
Share on other sites

ok i have been messing with this bit

<center><h1>Newsletter</h1></center>

 

it display ok with out the tags but if i just have center tags that adds a small gap but when i ass the h1 tags it adds the big gap but if i have both then it is just the big gap so the css i posted earlier is not working.

 

anyone know what i could try?

Link to comment
https://forums.phpfreaks.com/topic/230808-nl2br/#findComment-1188460
Share on other sites

Try cyberrobot's idea first, he has good eyes I didn't see the double colon yesterday.

 

You can also try  <h1 style="margin: 0; padding: 0; text-align:center;">Newsletter</h1>  if you have a problem with inheritence.

 

But this will make your code bulky in the long run if you use it a lot, your's should work once you remove the colon, use firebug to check for inheritence.

Link to comment
https://forums.phpfreaks.com/topic/230808-nl2br/#findComment-1188625
Share on other sites

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.