Jump to content

Archived

This topic is now archived and is closed to further replies.

shimano55

Mysql Result Formatting

Recommended Posts

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:
[code]function newsPost($post) {
    return nl2br(htmlspecialchars($post));
  }[/code]

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

Thanks in advance,
shimano55

Share this post


Link to post
Share on other sites
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. :)
[code]p
{
text-indent: 10px
}[/code]
will indent the first line.

Share this post


Link to post
Share on other sites
@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

Share this post


Link to post
Share on other sites
Change your function to the following:
[code]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;
}[/code]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.