+ Post New Thread
Results 1 to 6 of 6
Web Development Thread, Converting Content of Text area as HTML in Coding and Web Development; I have a form that is submitting for the noticeboard I have made - Edu-it has pointed out it doesn't ...
  1. #1

    glennda's Avatar
    Join Date
    Jun 2009
    Location
    Sussex
    Posts
    7,817
    Thank Post
    272
    Thanked 1,138 Times in 1,034 Posts
    Rep Power
    350

    Converting Content of Text area as HTML

    I have a form that is submitting for the noticeboard I have made - Edu-it has pointed out it doesn't do lines very well! as the text area is submitting to the database as simple text. Is there a way I can convert the text from the text area into HTML before submitting to the database?

    Or even as it echos the content of the database convert the text into HTML?

    Toby

  2. #2

    webman's Avatar
    Join Date
    Nov 2005
    Location
    North East England
    Posts
    8,412
    Thank Post
    642
    Thanked 963 Times in 663 Posts
    Blog Entries
    2
    Rep Power
    326
    PHP function nl2br will convert new lines in plain text to <br> HTML tags

  3. Thanks to webman from:

    glennda (11th February 2011)

  4. #3

    glennda's Avatar
    Join Date
    Jun 2009
    Location
    Sussex
    Posts
    7,817
    Thank Post
    272
    Thanked 1,138 Times in 1,034 Posts
    Rep Power
    350
    Webman to the rescue. Cheers. - also what can i use to convert the text which has http:// infront - I'm guessing it needs some processing to covert the link address to html?

  5. #4

    webman's Avatar
    Join Date
    Nov 2005
    Location
    North East England
    Posts
    8,412
    Thank Post
    642
    Thanked 963 Times in 663 Posts
    Blog Entries
    2
    Rep Power
    326
    Use a regular expression

    Code:
    $text = preg_replace('@(https?://([-\w\.]+)+(:\d+)?(/([\w/_\.]*(\?\S+)?)?)?)@', '<a href="$1">$1</a>', $text);
    Source: http://snipplr.com/view/2371/regex-r...o-match-a-url/

  6. Thanks to webman from:

    glennda (11th February 2011)

  7. #5

    glennda's Avatar
    Join Date
    Jun 2009
    Location
    Sussex
    Posts
    7,817
    Thank Post
    272
    Thanked 1,138 Times in 1,034 Posts
    Rep Power
    350
    Thank you!

  8. #6

    glennda's Avatar
    Join Date
    Jun 2009
    Location
    Sussex
    Posts
    7,817
    Thank Post
    272
    Thanked 1,138 Times in 1,034 Posts
    Rep Power
    350
    Do you know a way to change it for if staff just post Google rather then Google

    I tried

    Code:
    $text = preg_replace('@(wwww([.]+)+(:\d+)?(/([\w/_\.]*(\?\S+)?)?)?)@', '<a href="$1">$1</a>', $text);
    But that didn't quite work!

SHARE:
+ Post New Thread

Similar Threads

  1. Convert Text On Image Into Editable Text
    By DaveP in forum General Chat
    Replies: 4
    Last Post: 30th May 2013, 09:10 AM
  2. Sending HTML content via an email contact form
    By AnnDroyd in forum Web Development
    Replies: 2
    Last Post: 10th May 2010, 12:43 PM
  3. Content Creation - wont save / add to html
    By callan1974 in forum EduGeek Joomla 1.0 Package
    Replies: 1
    Last Post: 7th July 2009, 03:27 AM
  4. Converting text to number
    By tw15ns in forum Office Software
    Replies: 4
    Last Post: 26th May 2009, 08:19 PM
  5. Centering a scrolling text box in HTML
    By PWaite in forum Web Development
    Replies: 15
    Last Post: 19th January 2009, 09:53 AM

Thread Information

Users Browsing this Thread

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

Posting Permissions

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