Page 1 of 1
Store html text format in database & retrieve - problem!
Posted: Thu Aug 21, 2003 10:15 am
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...!!
Posted: Thu Aug 21, 2003 10:27 am
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?
Re: Store html text format in database & retrieve - prob
Posted: Thu Aug 21, 2003 10:40 am
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.
Posted: Thu Aug 21, 2003 10:49 am
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.
Posted: Thu Aug 21, 2003 10:53 am
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
why bother
Posted: Thu Aug 21, 2003 1:22 pm
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