Reply
saving html tags in mySQL
Old 05-11-2008, 12:38 AM saving html tags in mySQL
Novice Talker

Posts: 12
I need to save something like this in a database table:

Title

Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text .

Title 2

Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text .

etc.


The titles will be <h2> and I'd like the texts to be <p>.

I'd like to know how you would save this in a database table. Would you include the tags with the texts? I mean, insert the <h2> and <p> tags with the texts.

I tried to detect the crlf with chr(13) to add the <p></p> automatically when I retrieve the field and it works, but I have problems with the titles, because it adds a paragraph there too (like <p><h2>Title</h2></p>).

Any help or suggestion will be much appreciated

Thanks a lot
feelice is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
     
Old 05-11-2008, 02:13 AM Re: saving html tags in mySQL
addonchat's Avatar
Skilled Talker

Posts: 97
Name: Chris Duerr
How is the data being presented? Is it just one file/form entry in the format you've described? If it's a form, the 'title' and 'text' should be entered in separate input fields so you don't have to parse.

Otherwise, you have to be certain the data will always be provided in the format you've described ('title' followed by two CR/LF's, followed by 'text' followed by two CR/LF's. etc..) -- not a very standard protocol and if you have control over how the data is being provided, I suggest changing it.

If you're stuck with that though, you're going to need to maintain state, so you'll need a loop containing your string replacement function(s) or regular expression(s). First, I would replace translate any \r\n combos to just a plain old \n; secondly I would replace your double \n\n's with a single \n -- there is really no need once you get to the parsing this to have multiple CR/LF's. After that, loop through each line of text, assuming the first line is a title, the second your text, until the loop is complete.

And about storing the data in a database, I would not store the HTML content in the database. You may decide to change how the content is displayed sometime down the line. Let the script that displays the output control this. In this case, use your database for storing your data, not your markup.
__________________
Chris Duerr
AddonChat Java Chat Software
http://www.addonchat.com/ - Affiliate Program
addonchat is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to saving html tags in mySQL
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.12455 seconds with 13 queries