View Full Version : replacing something. I need text that is entered into mysql to keep their returns....
Trusten
09-04-2002, 12:38 PM
http://www.php.net/manual/en/function.preg-replace.php
ok, i'm making a form where people can upload their story. thing is, when you cut and paste, the story is in tact, fine, but once it enters the database and is reposted, there are NO returns, no paragraphs, everything runs together.
i tried using that link to figure it out, but i don't get it, do i try to put a code on the page where you enter the data, the page where the data is entered into the mysql table, or on the page that posts it?
much obliged...
mordred
09-04-2002, 03:09 PM
You can make use of the nl2br() funtion - that will convert any newline character of a string to a HTML linebreak (<br />). As to the stage where you should apply this, I would do it at the moment you pull the data from the db and display it on your webpage.
Can't follow you on the paragraph thing though... how do you distinguish a paragraph in the string that contains form data?
Trusten
09-04-2002, 03:23 PM
well your sugguestion is good though. i'd try that. but how do i write it?
mordred
09-04-2002, 03:26 PM
$str = "this is a
string with
line breaks
in it.
yo.";
echo nl2br($str);
like this?
Trusten
09-04-2002, 03:27 PM
well with a form, they placed it into the database table.
the column is called 'fiction'
when they visit the page, it retrieves 'fiction' and posts it,
it also posts other things such as the fiction_title etc. etc. etc.
so how would i write it now?
mordred
09-04-2002, 03:34 PM
Well you take the usual code you have for retrieving the story's data from the article and apply that function on the fields you want to.
like
$sql = "SELECT * FROM stories WHERE story_id = $storyId";
$result = mysql_query($sql);
if ($result) {
$row = mysql_fetch_assoc($result);
echo "Title: " . nl2br($row['fiction_title']) . "<br />";
echo nl2br($row['fiction']);
}
Trusten
09-04-2002, 03:36 PM
THANK YOUUUU!!
GOT IT WORKING!!
Trusten
09-04-2002, 03:37 PM
well, i didn't get that post before i fiddled with it. it's working at least. don't know how though
tanks
i'll look over your last post
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.