I know the person who's probly going to help me with this, is getting sick of it :P!!!
But anyway
I have a Text box in PHP on my website for entering a post into a blog, but I want it to automaticly add <br>'s on new lines when Enter is pressed!
Any code for this, as now I have added stripslashes and htmlspechcahars, it just shows <br>!!!!!
Text Boxes & <br> PHP
Started by Bioshox, Feb 16 2010 11:27 AM
7 replies to this topic
#1
Posted 16 February 2010 - 11:27 AM
|
|
|
#2
Guest_Jaan_*
Posted 16 February 2010 - 02:29 PM
Guest_Jaan_*
Well.. you can use
You needed something like this ?
$str = "I think I have <br />found a solution<br />to my problem!";
$str = str_replace("<br />", "\n", $str);
echo $str;
You needed something like this ?
#3
Posted 17 February 2010 - 12:55 AM
Haha bioshock :P
If you save the text of a textbox inside the database and retrieve it again on another page of your website to show it ( for example news or posts that you want to add to a database by typing it in a textbox and then show on your website ), if this is what you're trying to do, the function nl2br can be used which will convert normal enter inputs automaticly into br's (<br>).
So say you've got a post retrieved from the database and put in a variable $post, then to show it correctly ( enters replaced by html <br> tags to show these enters properly ):
EDIT: misread your post, I think this is the reverse effect of what you mean, Jaan's solution should work I suppose :)
However I'm not quite sure how come it shows <br> inside your posts? As I suppose you just insert a message like this to the database:
As there's no need to put <br> html tags inside your post, you can just use normal enters and use the function nl2br as mentioned above into automaticly convert them to proper html. So if you did add <br> tags to your post manually to add enters for your posts, that's not neccessarely needed. However Im not sure how you wanted your system to work, so ^^
If you save the text of a textbox inside the database and retrieve it again on another page of your website to show it ( for example news or posts that you want to add to a database by typing it in a textbox and then show on your website ), if this is what you're trying to do, the function nl2br can be used which will convert normal enter inputs automaticly into br's (<br>).
So say you've got a post retrieved from the database and put in a variable $post, then to show it correctly ( enters replaced by html <br> tags to show these enters properly ):
echo nl2br($post);
EDIT: misread your post, I think this is the reverse effect of what you mean, Jaan's solution should work I suppose :)
However I'm not quite sure how come it shows <br> inside your posts? As I suppose you just insert a message like this to the database:
Quote
Line 1 of my message
Line 2 of my message
Line 2 of my message
As there's no need to put <br> html tags inside your post, you can just use normal enters and use the function nl2br as mentioned above into automaticly convert them to proper html. So if you did add <br> tags to your post manually to add enters for your posts, that's not neccessarely needed. However Im not sure how you wanted your system to work, so ^^
#4
Posted 17 February 2010 - 01:39 AM
This works but now it dosent include line breaks and everything is just one paragraph!
Jaans code didn't work at first so I modified it to this
As you can see it's replacing <br>'s with spaces, I tried putting /n in put it just displayed '/n'
Jaans code didn't work at first so I modified it to this
$row['body'] = str_replace("<br>", " ", $row['body']);
As you can see it's replacing <br>'s with spaces, I tried putting /n in put it just displayed '/n'
#5
Posted 17 February 2010 - 04:10 AM
it's supposed to be \n not /n
__________________________________________
I study Information Systems at Karlstad University when I'm not on CodeCall
I study Information Systems at Karlstad University when I'm not on CodeCall
#6
Posted 17 February 2010 - 06:45 AM
Orjan said:
it's supposed to be \n not /n
It still didn't work D':
#7
Posted 17 February 2010 - 06:56 AM
Are you using <input type="text"> or are you using <textarea> ? There is a big difference between them!
__________________________________________
I study Information Systems at Karlstad University when I'm not on CodeCall
I study Information Systems at Karlstad University when I'm not on CodeCall
#8
Posted 17 February 2010 - 07:03 AM
<textarea> for the Body
and <input type="text"> for the titles :)
and <input type="text"> for the titles :)


Sign In
Create Account


Back to top









