Store html text format in database & retrieve - problem!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
rock
Forum Newbie
Posts: 2
Joined: Thu Aug 21, 2003 10:15 am

Store html text format in database & retrieve - problem!

Post by rock »

hi,

I have to make a static page to dynamic using php - mysql. the page has hyperlinks . I want that a front end user to write the text which may have the hyperlinks in it. This has to be stored in the database.

Now, from the database I have to retrieve this record. The hyperlinks(if it is there) should be displayed then. Is there any method to store html text in the database & then retrieve from the database(with all the html tags) in the web page.

Please advice me, how to do this. Any kind of help will be highly appreciated. Thanx in advance...!!
User avatar
greenhorn666
Forum Commoner
Posts: 87
Joined: Thu Aug 14, 2003 7:14 am
Location: Brussels, Belgium

Post by greenhorn666 »

I don't think I got your problem right?
You want to parse a plain text for URL's so that being displayed this urls are clickable (get the surrounding <a> tags)?
Is that it?
User avatar
Rook
Forum Newbie
Posts: 10
Joined: Thu Aug 21, 2003 10:40 am
Location: Euless, Tx.
Contact:

Re: Store html text format in database & retrieve - prob

Post by Rook »

You shouldn't have a problem with storing text that contains HTML code in a text database field. I've got a site that routinely does this. I'm using PHP 4.1.2 and MySQL 3.23.56.

Looking at my code, I have a form with a textarea field in which the user writes the html code. Other than performing a standard SQL insert query, the only special functions I run on the submitted HTML is the following:

Code: Select all

<?php
$codeBody = stripslashes($_POST['code_body']);
$codeBody = mysql_escape_string($codeBody);
?>
Then when you pull the 'code body' from the database you can simply use echo or print to output it to the browser.

I hope this helps!

- Rook.
Last edited by Rook on Thu Aug 21, 2003 10:51 am, edited 1 time in total.
rock
Forum Newbie
Posts: 2
Joined: Thu Aug 21, 2003 10:15 am

Post by rock »

ya, but not this much. It may be any html tag like <b>CNN</b>

for eg. the following text has to be stored in the database

1) CNN
2) visit CNN for more details.

here in 1) CNN is bold.
and 2) CNN is linked to http://www.cnn.com

the above tow line has to be displayed in the web page. So it can be any html tag.
User avatar
greenhorn666
Forum Commoner
Posts: 87
Joined: Thu Aug 14, 2003 7:14 am
Location: Brussels, Belgium

Post by greenhorn666 »

If the tags are there, put the string in the DB and the tags will stay there... I don't get you, sorry... I'm off
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

why bother

Post by phpScott »

If the data you are are getting is 1)the site name to link to and 2) the description that they want to show why not simply store the data in the db and format the anchor tags using php. It would save the hassle of trying to store tags and anything screwy that might happen because of quoting or / issues



phpScott
Post Reply