I know the person who's probly going to help me with this, is getting sick of it!!!
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>!!!!!
Well.. you can use
You needed something like this ?Code:$str = "I think I have <br />found a solution<br />to my problem!";
$str = str_replace("<br />", "\n", $str);
echo $str;
Haha bioshock
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 supposeCode:echo nl2br($post);
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, soLine 1 of my message
Line 2 of my message![]()
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'Code:$row['body'] = str_replace("<br>", " ", $row['body']);
it's supposed to be \n not /n
__________________________________________
I study Information Systems at Karlstad University when I'm not on CodeCall
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
<textarea> for the Body
and <input type="text"> for the titles![]()
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks