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
https://forums.phpfreaks.com/topic/8207-mysql-result-formatting/
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
https://forums.phpfreaks.com/topic/8207-mysql-result-formatting/#findComment-29988
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
https://forums.phpfreaks.com/topic/8207-mysql-result-formatting/#findComment-30016
Share on other sites

Archived

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

×
×
  • 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.