Welcome Guest, Not a member yet? Register   Sign In
How to keep paragraph breaks
#1

[eluser]Mike Cocklin[/eluser]
Ok,

I am new to CI but I really love it already. I guess I am missing something but here is my problem.

I have two text areas that I am posting to fields in my database. If I create paragraphs within the text boxes and save them to the database and look at the raw value of the field I get the folowing

'This is the second paragraph. It will let me know what happens now. Maybe it will look really bad.\n\nI really hope it doesn\'t as i don\'t know what i will do if it does.'

Note the \n\n

When i echo this back to a view I can't see any paragraph breaks Sad What am I Missing?

Any Help would be much appreciated
#2

[eluser]Alexandru M.[/eluser]
Try applying nl2br to the textareas' content before inserting , that should do it. "\n" is the new-line character in windows , but to see new lines in html you need the <br /> tag.
Code:
$data = nl2br($this->input->post('my_textarea'));
Then continue with the insertion in your DB.
#3

[eluser]techgnome[/eluser]
Or... do it on the way back out of the database. I prefer to store the raw text in the database... makes editing easier later... then do the html encoding when displaying it.

-tg
#4

[eluser]Mike Cocklin[/eluser]
[quote author="techgnome" date="1286696374"]Or... do it on the way back out of the database. I prefer to store the raw text in the database... makes editing easier later... then do the html encoding when displaying it.

-tg[/quote]

I prefere that idea. How do i do this on the way out?

What i mean is, this field becomes part of an array in my controller

Code:
$data['monthlyTheme'] = $this->newspaper_model->GetThisTheme($options = array('theme_date' => $thisMonth, 'theme_group_id' => $theme_group_id));

in my view it is displayed in a for each loop

Code:
&lt;?php if(isset($monthlyTheme) && is_array($monthlyTheme) && count($monthlyTheme)>0):?&gt;
&lt;?php foreach($monthlyTheme as $item ): ?&gt;
<p class="firstpara">&lt;?php echo $item->theme_texta;?&gt;</p>
<p class="standardpara">&lt;?php echo $item->theme_textb;?&gt;</p>
&lt;?php endforeach; ?&gt;
&lt;?php else: ?&gt;
<span style="color:white">Awaiting Theme</span>
&lt;?php endif; ?&gt;

Many thanks
#5

[eluser]Mike Cocklin[/eluser]
Ignore me, I am so slow sometimes!!!!

<p class="firstpara">&lt;?php echo nl2br($item->theme_texta);?&gt;</p>
<p class="standardpara">&lt;?php echo nl2br($item->theme_textb);?&gt;</p>

This does it it doesn't it.

Been focusing on it for so long couldn't see the wood for the trees. Many thanks to you both for pointing me in the right direction.




Theme © iAndrew 2016 - Forum software by © MyBB