Closed Thread
Results 1 to 8 of 8

Thread: Text Boxes & <br> PHP

  1. #1
    Bioshox is offline Programmer
    Join Date
    Oct 2009
    Location
    Manchester, UK
    Posts
    196
    Rep Power
    10

    Text Boxes & <br> PHP

    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>!!!!!

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Location
    Advertising world
    Posts
    Many

     
  3. #2
    Jaan Guest

    Re: Text Boxes & <br> PHP

    Well.. you can use

    Code:
    $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 ?

  4. #3
    webcodez's Avatar
    webcodez is offline Programmer
    Join Date
    Feb 2010
    Posts
    148
    Rep Power
    0

    Re: Text Boxes & <br> PHP

    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 ):

    Code:
    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:

    Line 1 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

  5. #4
    Bioshox is offline Programmer
    Join Date
    Oct 2009
    Location
    Manchester, UK
    Posts
    196
    Rep Power
    10

    Re: Text Boxes & <br> PHP

    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

    Code:
    	$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'

  6. #5
    Join Date
    Sep 2007
    Location
    Karlstad, Sweden
    Posts
    3,082
    Blog Entries
    7
    Rep Power
    42

    Re: Text Boxes & <br> PHP

    it's supposed to be \n not /n
    __________________________________________
    I study Information Systems at Karlstad University when I'm not on CodeCall

  7. #6
    Bioshox is offline Programmer
    Join Date
    Oct 2009
    Location
    Manchester, UK
    Posts
    196
    Rep Power
    10

    Re: Text Boxes & <br> PHP

    Quote Originally Posted by Orjan View Post
    it's supposed to be \n not /n

    It still didn't work D':

  8. #7
    Join Date
    Sep 2007
    Location
    Karlstad, Sweden
    Posts
    3,082
    Blog Entries
    7
    Rep Power
    42

    Re: Text Boxes & <br> PHP

    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

  9. #8
    Bioshox is offline Programmer
    Join Date
    Oct 2009
    Location
    Manchester, UK
    Posts
    196
    Rep Power
    10

    Re: Text Boxes & <br> PHP

    <textarea> for the Body

    and <input type="text"> for the titles

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. CSS Styling Resizable Text Boxes
    By bbqroast in forum Website Design
    Replies: 2
    Last Post: 04-13-2011, 09:36 PM
  2. Help with calculations using text boxes.
    By dionne in forum Visual Basic Programming
    Replies: 2
    Last Post: 02-18-2010, 07:00 AM
  3. Resize Text Boxes
    By Sniped Sniper in forum Visual Basic Programming
    Replies: 4
    Last Post: 09-04-2009, 03:06 PM
  4. Report from Some text Boxes ??
    By _root in forum C# Programming
    Replies: 1
    Last Post: 05-22-2009, 05:04 AM
  5. Multi-format text boxes
    By Chambered in forum Visual Basic Programming
    Replies: 3
    Last Post: 02-28-2008, 01:32 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts