Jump to content

Mysql Result Formatting


shimano55

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
Link to comment
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.
Link to comment
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
Link to comment
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]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.