How to echo a paragraph text field using php

webjusti

New Member
Messages
13
Reaction score
0
Points
1
Hi, I am using MySQL, Apache and have stored in it a paragraph text field. I need to echo this filed using php. When I use: <? echo { "$current_user->large paragraph" ; } ?> it gives me a string with no <br> breaks in it, just all the text in one block. How can I echo this paragraph text so that it will recognize the spaces and echo it correctly?

Thanks, Carlos
 

Anna

I am just me
Staff member
Messages
11,751
Reaction score
581
Points
113
Moved to "Scripts, 3rd Party Apps, and Programming" since this is a programming question.
 

descalzo

Grim Squeaker
Community Support
Messages
9,373
Reaction score
326
Points
83
How are you generating the text?
Yourself?
User input?
If your stored text has paragraph breaks stored as "\n" newlines, you will have to process the stored text to add the < br > tags.
Or you can pre-process the text to add the < br > tags before you put it into the data base (makes for a more responsive display of the text).
 

otakupag

New Member
Messages
4
Reaction score
0
Points
1
You can use text or blob in data type. Then insert HTML code in it. You can use HTMLPurifier to avoid hackings. You can message me anytime for help :)
 

ddnhf43

New Member
Messages
19
Reaction score
0
Points
1
There is a built in function PHP that adds turns new lines into line breaks. Try this sample:

Code:
<?php echo nl2br($current_user->large paragraph); ?>

In PHP, you should NEVER use short tags as it's a bad practice. You never know if a server has them enabled or not so I suggest getting into the practice of using the full tags. You also don't need the echo { "$current_user->large paragraph"; } as that's not needed, I suggest you take a look into learning the best practices of PHP. Hope I helped, feel free to message me if you need any help with PHP.
 

Skizzerz

Contributors
Staff member
Contributors
Messages
2,928
Reaction score
118
Points
63
Short "echo" tags, e.g. <?= ?> are always available starting in PHP 5.4, so you can use those if you'd like. Beyond that, remember to always escape any user-provided strings before outputting them to the browser so that you are not vulnerable to HTML injection/XSS attacks. As @ddnhf43 suggested, learning some best practices for PHP is great, as it would help you avoid a lot of the pitfalls in the language
 
Top