Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Hold carriage returns in PHP MySQL database?

Explorer ,
Nov 27, 2007 Nov 27, 2007
I'm creating a limited news database for a not-for-profit site and I want to let admin users write a long entry which may include multiple paragraphs (i.e. carriage returns) and even bold text for subheadings would be nice. I haven't been able to find out the proper code and DB settings to allow users to do this.

Anyone have a simple solution?
TOPICS
Server side applications
741
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 28, 2007 Nov 28, 2007
Justin from Indiana wrote:
> I'm creating a limited news database for a not-for-profit site and I want to
> let admin users write a long entry which may include multiple paragraphs (i.e.
> carriage returns) and even bold text for subheadings would be nice.

Carriage returns are stored normally in a database. However, they seem
to disappear when displayed onscreen. This is because HTML ignores extra
whitespace. If you use View Source in a browser, you'll see the carriage
returns are actually there. The solution is simple with PHP. Just pass
the material retrieved from the database to nl2br().

http://docs.php.net/manual/en/function.nl2br.php

If you're using Dreamweaver CS3, you can add nl2br() to dynamic text by
double-clicking the Dynamic Text listing in the Server Behaviors panel,
and selecting Convert - New Lines to BRs from the Format menu.

To store bold text in the database, just surround the text with <strong>
tags.

--
David Powers, Adobe Community Expert
Author, "The Essential Guide to Dreamweaver CS3" (friends of ED)
Author, "PHP Solutions" (friends of ED)
http://foundationphp.com/
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 28, 2007 Nov 28, 2007
The way I handle text formatting with dynamic data is to carefully construct
your DB with formatting in mind
Create separate fields for headlines and copy. When you call the data to
your web page surround the heading with the desired tag. Of course you will
not always have a heading, so, to eliminate empty spaces add a conditional
statement to ignore the field if it is null.

like this:

database:
news_id
news_headline1
news_copy1
news_headline2
news_copy2

web page:
<?php if (strlen($row_getNews['news_headline1']) > 0) {?>
<h3><?php echo $row_getNews['news_headline1']; ?></h3>
<?php }?>
<p><?php echo $row_getNews['news_copy1']; ?></p>
<?php if (strlen($row_getNews['news_headline2']) > 0) {?>
<h3><?php echo $row_getNews['news_headline2]; ?></h3>
<?php }?>
<?php if (strlen($row_getNews['news_copy2']) > 0) {?>
<p><?php echo $row_getNews['news_copy2']; ?></p>
<?php }?>

Jeff


"Justin from Indiana" <webforumsuser@macromedia.com> wrote in message
news:fiimo4$33$1@forums.macromedia.com...
> I'm creating a limited news database for a not-for-profit site and I want
> to
> let admin users write a long entry which may include multiple paragraphs
> (i.e.
> carriage returns) and even bold text for subheadings would be nice. I
> haven't
> been able to find out the proper code and DB settings to allow users to do
> this.
>
> Anyone have a simple solution?
>


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 30, 2007 Nov 30, 2007
That would work fine if you have a standard paragraph by paragraph format. But the user posting stories is going to need more flexibility for bulleted lists, etc.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 30, 2007 Nov 30, 2007
Justin from Indiana wrote:
> But the user posting stories is going to need more flexibility for bulleted lists, etc.

In that case, you need to store the HTML in the database. You might want
to look into FCKEditor ( http://www.fckeditor.net/).

--
David Powers, Adobe Community Expert
Author, "The Essential Guide to Dreamweaver CS3" (friends of ED)
Author, "PHP Solutions" (friends of ED)
http://foundationphp.com/
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 04, 2007 Dec 04, 2007
LATEST
Took a quick look. It appears to work much like the interface for these posts. Hope it's not to problematic to work into my admin pages...
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines