Results 1 to 8 of 8

Thread: Text formatting Question

  1. #1
    Senior Member
    Join Date
    Jul 2003
    Posts
    1,066
    Thanks
    1
    Thanked
    0 times in 0 posts

    Text formatting Question

    I want to put text into a database then retrive it. This is showing my lack of basic html knowledge but when I lift it out onto a page how do you go about formatting it properly without having to manually add <BR> tags to the text when I enter it into a form?

    Ive decided to try web design again after a long time of basically always intending to do something but never actually doing it. So the world of CSS is being slowly opened to me and Im gonna try and do a proper database driven web site rather than just arsing about with asp and not actually DOING anything with it.

    If anyone cares to make constructive comments or even just tell me how crap the site is have a gander :

    http://www22.brinkster.com/roguesaber/kellsangel/

  2. #2
    Senior Member Kezzer's Avatar
    Join Date
    Sep 2003
    Posts
    4,863
    Thanks
    12
    Thanked
    5 times in 5 posts
    If you want a database you'd be better of using MySQL and PHP which is what i'm doing at the mo' although the PHP side of it is a lot harder than CSS. Even on my database i have to use HTML to make new paragraphs and so forth. It is possible to make the formatting of the page by just hitting return (look at hexus reply box for example)

  3. #3
    HEXUS.net Webmaster
    Join Date
    Jul 2003
    Location
    UK
    Posts
    3,108
    Thanks
    1
    Thanked
    0 times in 0 posts
    there's a PHP function called nl2br() short for new line to br which basically takes line breaks entered into a database and automatically creates the <br> tags. I'm not sure if there is a similar function for ASP though

  4. #4
    Senior Member Shad's Avatar
    Join Date
    Jul 2003
    Location
    In front
    Posts
    2,782
    Thanks
    23
    Thanked
    42 times in 25 posts
    Quote Originally Posted by Az
    I'm not sure if there is a similar function for ASP though
    There isn't, but we can write one:


    Code:
    Function nl2br(txt)
        rslt = txt
        rslt = Replace(rslt,vbcrlf,"<br>")
        rslt = Replace(rslt,"<br><br>","</p><p>")
        rslt = "<p>" & rslt & "</p>"
        nl2br = rslt
    End function
    Hopefully it's obvious what's going on in there...
    Simon


  5. #5
    Senior Member
    Join Date
    Jul 2003
    Posts
    1,066
    Thanks
    1
    Thanked
    0 times in 0 posts
    Think I have a vague idea whats happening...

    Couldn't quickly break it down for me? A guy has to learn

  6. #6
    Senior Member Shad's Avatar
    Join Date
    Jul 2003
    Location
    In front
    Posts
    2,782
    Thanks
    23
    Thanked
    42 times in 25 posts
    Quote Originally Posted by RoGuE|SaBeR
    Think I have a vague idea whats happening...

    Couldn't quickly break it down for me? A guy has to learn
    Code:
    Function nl2br(txt) 'pass the text block you want to convert as parameter txt to function nl2br
        rslt = txt 'assign paramater to local variable
        rslt = Replace(rslt,vbcrlf,"<br>") 'replace crlf's with breaks
        rslt = Replace(rslt,"<br><br>","</p><p>") 'replace two breaks with a new paragraph
        rslt = "<p>" & rslt & "</p>" 'put paragraph tags around the result
        nl2br = rslt 'output result
    End function
    Simon


  7. #7
    Pixel Abuser Spunkey's Avatar
    Join Date
    Nov 2003
    Location
    Milton Keynes
    Posts
    1,523
    Thanks
    0
    Thanked
    0 times in 0 posts
    if your text in the database is being entered in through a <TEXTAREA> tag, theres a property called 'wrap'. By default (in IE) this is set to soft which will wrap text in the box, but ignore carriage returns when sent via HTTP, and therefore into the database. if you use wrap="hard" it will send any carriage returns, and will put them in the database.
    for a better explanation try the bottom of this page --> http://www.blooberry.com/indexdot/ht...t/textarea.htm

    The box used by this forum is an example - it uses hard wrapping to allow people to put text on more than 1 line.

    If you're not using a textarea tag then this aint a lot of help

    PS *swings pocket watch* ASP is good, use it

  8. #8
    Richard Allen Evans mr_anderson187's Avatar
    Join Date
    Dec 2003
    Location
    Norfolk 'n chance
    Posts
    2,133
    Thanks
    3
    Thanked
    0 times in 0 posts
    lol @ Harrison,

    inspiration, from a mr_anderson187

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Validating text entered into a VB text box
    By Dorza in forum Software
    Replies: 9
    Last Post: 09-06-2006, 10:15 AM
  2. Has anyone else got this text ?
    By Agent in forum General Discussion
    Replies: 10
    Last Post: 15-12-2003, 07:19 PM
  3. Quick question re formatting.
    By quarryman in forum PC Hardware and Components
    Replies: 3
    Last Post: 04-12-2003, 12:46 AM
  4. Passing variables, writing text files, etc
    By daverobev in forum Software
    Replies: 17
    Last Post: 03-12-2003, 03:49 PM

Posting Permissions

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