Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

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

Posts: 12
Trades: 0
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
 
 
Register now for full access!
Old 05-11-2008, 03:13 AM Re: saving html tags in mySQL
addonchat's Avatar
Super Talker

Posts: 115
Name: Chris Duerr
Trades: 0
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

Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE
addonchat is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to saving html tags in mySQL
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB 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.11839 seconds with 12 queries