Jump to content


Photo

Mysql Result Formatting


  • Please log in to reply
3 replies to this topic

#1 shimano55

shimano55
  • Members
  • Pip
  • Newbie
  • 8 posts
  • LocationLos Angeles, CA

Posted 23 April 2006 - 10:24 PM

Hey everyone. I'm building a CMS and am working on the formatting of news posts. I have nl2br() to add breaks to the result, but I'm at a loss when it comes to indents. When I submit the news post, I use 5 spaces at the beginning, and I can see 5 spaces in the field on phpmyadmin. But when the result is displayed on the site, there are only the spaces in between words and sentences. No indent.

This is my current format function:
function newsPost($post) {
    return nl2br(htmlspecialchars($post));
  }

What do I have to add to it to get the ident spaces to show?

Thanks in advance,
shimano55
PHP is my life.

#2 bbaker

bbaker
  • Members
  • PipPipPip
  • Advanced Member
  • 127 posts
  • LocationNY

Posted 24 April 2006 - 02:24 AM

are you using " " or just pressing the space bar? If pressing the space bar, your browser will ignore the "whitespace" of the spaces.

OR

you can do it correctly & use CSS to do your indents. :)
p
{ 
text-indent: 10px
}
will indent the first line.

#3 shimano55

shimano55
  • Members
  • Pip
  • Newbie
  • 8 posts
  • LocationLos Angeles, CA

Posted 24 April 2006 - 05:12 AM

@css: Yes, but what if the news post has more than one paragraph?

I'm making an admincp for the news posts. So I need it to be by just hitting the spacebar. As I said, the spaces are there in phpmyadmin. Is there no other way to accomplish this?

Thanks,
shimano55
PHP is my life.

#4 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 24 April 2006 - 08:19 AM

Change your function to the following:
function newsPost($post)
{
    $post = nl2br(htmlspecialchars($post));

    //convert two spaces into "  " this will force the browser to not ignore the spaces
    $post = str_replace("  ", "  ", $post);

    return $post;
}





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users